K
K
Kirill H2017-06-20 21:40:43
C++ / C#
Kirill H, 2017-06-20 21:40:43

Why are functions without parameters not handled in UnitTests?

I created a static library in c++, wrote tests for it, everything was fine. The question was to transfer everything to the CLR console project, I just copied the files from my library there, everything worked fine. I decided to finish UNIT TESTS, but it’s not a task here, I connected all this beauty to the application, everything is fine, but it started to give a linker error 2019, as I understand it, it probably doesn’t see cpp-shniks or what? By the fact that when I cursed at the default constructors, where the difenishen was placed in cpp, I wrote it in the header and everything smelled.
You never know, the code of one of the classes:

Point.h
#pragma once

namespace Battleship
{

  class Point
  {
  private:

    unsigned iX;
    unsigned iY;

  public:

    Point() : iX(0), iY(0) { };
    Point(int X, int Y) : iX(X), iY(Y) { };
    const int X();
    const int Y();
    void Set(int X, int Y);

    bool operator==(Point Value);
    bool operator!=(Point Value);

    void MoveUp();
    void MoveDown();
    void MoveLeft();
    void MoveRight();

  };
}

Point.cpp
#include "Point.h"

const int Battleship::Point::X()
{
  return iX;
}

const int Battleship::Point::Y()
{
  return iY;
}

void Battleship::Point::Set(int X, int Y)
{
  if (X >= 0 && Y >= 0)
  {
    iX = X;
    iY = Y;
  }
  else
  {
    return;
  }
}

bool Battleship::Point::operator==(Point Value)
{
  if (this->iX == Value.iX && this->iY == Value.iY)
  {
    return true;
  }
  else
  {
    return false;
  }
}

bool Battleship::Point::operator!=(Point Value)
{
  if (!(*this == Value))
  {
    return true;
  }
  else
  {
    return false;
  }
}

void Battleship::Point::MoveUp()
{
  iY--;
}

void Battleship::Point::MoveDown()
{
  iY++;
}

void Battleship::Point::MoveLeft()
{
  iX--;
}

void Battleship::Point::MoveRight()
{
  iX++;
}

unit test
#include "stdafx.h"
#include "CppUnitTest.h"
#include "Point.h"

using namespace Microsoft::VisualStudio::CppUnitTestFramework;
using namespace Battleship;

namespace BattleShipUnitTests
{		
  TEST_CLASS(UnitTest1)
  {
  public:
    
    TEST_METHOD(TestMethod1)
    {
      Point Point1 = *new Point();        //Раньше тут вылетала 2019, пока я не поменял конструктор поумолчанию
      Point Point2 = *new Point(1, 2);

      Point1.MoveLeft();        //Теперь она вылетает тут...
    }

  };
}


Maybe I'm not catching up with something, I'll be grateful if someone explains, I want to learn and figure it out :)

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question