Test Template Method Source

Functions

TEST(TemplateMethodTest, ConcreteClass1Behavior)

Test the behavior of ConcreteClass1 when executing the template method.

Verifies that the template method correctly executes the algorithm flow and includes the specific steps and hook implementation of ConcreteClass1.

TEST(TemplateMethodTest, ConcreteClass2Behavior)

Test the behavior of ConcreteClass2 when executing the template method.

Verifies that the template method correctly executes the algorithm flow and includes the specific steps of ConcreteClass2.

TEST(TemplateMethodTest, HookFlexibility)

Test the flexibility of the hook in the template method.

Ensures that classes inheriting from AbstractClass can optionally override the hook method or rely on its default implementation.

TEST(TemplateMethodTest, AlgorithmStructure)

Test the overall algorithm structure of the template method.

Ensures that the base operations and required operations execute in the correct sequence as defined by the AbstractClass.

class OutputCapture

Utility class for capturing and validating output streams.

Captures the output sent to std::cout for validating test results involving console output.

Public Functions

inline void startCapture()

Begins capturing std::cout output.

inline std::string getCapturedOutput()

Stops capturing and retrieves the captured output.

Returns:

The captured output as a string.

Private Members

std::stringstream buffer

Internal buffer for capturing output.

std::streambuf *originalBuffer = std::cout.rdbuf()

Original buffer for std::cout.

Inner Classes