Unit testing series – Test scenario (Part 2)

For my unit testing series I have designed the following szenario.


#pragma once

class IWindowManager
{
public:
  virtual bool drawAt(unsigned startX, unsigned endX,
                      unsigned startY, unsigned endY) = 0;
};
  
class WindowManager : public IWindowManager
{
public:
  WindowManager(unsigned displaySizeX, unsigned displaySizeY);
  bool drawAt(unsigned startX, unsigned endX,
              unsigned startY, unsigned endY) override;
private:
  unsigned m_displaySizeX;
  unsigned m_displaySizeY;
};

#include "WindowManager.hpp"

WindowManager::WindowManager(unsigned displaySizeX, unsigned displaySizeY) :
  m_displaySizeX(displaySizeX), m_displaySizeY(displaySizeY) {}

bool WindowManager::drawAt(unsigned startX, unsigned endX,
                           unsigned startY, unsigned endY)
{
  bool ret = true;
  if (startX >= endX || endX > m_displaySizeX ||
      startY >= endY || endY > m_displaySizeY) ret = false;
  // ...
  return ret;
}

#pragma once
#include <memory>

class IWindowManager;

class UserInterface
{
public:
  UserInterface(std::shared_ptr<IWindowManager> windowMgr);
  bool loadWindow(unsigned startX, unsigned endX,
                  unsigned startY, unsigned endY);
private:
  std::shared_ptr<IWindowManager> m_windowMgr;
};

#include "UserInterface.hpp"
#include "WindowManager.hpp"

UserInterface::UserInterface(std::shared_ptr<IWindowManager> windowMgr)
  : m_windowMgr(windowMgr) {}

bool UserInterface::loadWindow(unsigned startX, unsigned endX,
                               unsigned startY, unsigned endY)
{
  return m_windowMgr->drawAt(startX, endX, startY, endY);
}

#include "WindowManager.hpp"
#include "UserInterface.hpp"
#include <memory>

int main()
{
  std::shared_ptr<IWindowManager> windowMgr(new WindowManager(1280, 1024));
  std::unique_ptr<UserInterface> userInter(new UserInterface(windowMgr));
  userInter->loadWindow(0, 1280, 0, 1024);
  // ...
  return 0;
}