Sane C++ Libraries
C++ Platform Abstraction Libraries
SC::TestCase Struct Reference

A test case that can be split into multiple sections. More...

#include <Testing.h>

Public Types

enum class  Execute {
  Default ,
  OnlyExplicit
}
 

Public Member Functions

 TestCase (TestReport &report, StringView testName)
 Adds this TestCase to a TestReport with a name. More...
 
bool recordExpectation (StringView expression, bool status, StringView detailedError=StringView())
 Records an expectation for a given expression. More...
 
bool recordExpectation (StringView expression, Result status)
 Records an expectation for a given expression. More...
 
bool test_section (StringView sectionName, Execute execution=Execute::Default)
 Starts a new test section. More...
 

Public Attributes

TestReportreport
 The TestReport object passed in the constructor. More...
 

Friends

struct TestReport
 

Detailed Description

A test case that can be split into multiple sections.

To create a test case derive from SC::TestCase and run tests in the constructor

Example:

namespace SC
{
struct ConsoleTest;
}
struct SC::ConsoleTest : public SC::TestCase
{
ConsoleTest(SC::TestReport& report) : TestCase(report, "ConsoleTest")
{
using namespace SC;
SmallVector<char, 512 * sizeof(native_char_t)> consoleConversionBuffer;
Console console(consoleConversionBuffer);
if (test_section("print"))
{
String str = StringView("Test Test\n");
console.print(str.view());
}
}
};
namespace SC
{
void runConsoleTest(SC::TestReport& report) { ConsoleTest test(report); }
} // namespace SC
char native_char_t
The native char for the platform (wchar_t (4 bytes) on Windows, char (1 byte) everywhere else )
Definition: PrimitiveTypes.h:34
A test case that can be split into multiple sections.
Definition: Testing.h:69
TestReport & report
The TestReport object passed in the constructor.
Definition: Testing.h:101
TestCase(TestReport &report, StringView testName)
Adds this TestCase to a TestReport with a name.
bool test_section(StringView sectionName, Execute execution=Execute::Default)
Starts a new test section.
Collects multiple TestCase and reports their results.
Definition: Testing.h:25

Member Enumeration Documentation

◆ Execute

enum class SC::TestCase::Execute
strong
Enumerator
Default 

Test is executed if all tests are enabled or if this specific one matches –test-section.

OnlyExplicit 

Test is executed only if explicitly requested with –test-section.

Constructor & Destructor Documentation

◆ TestCase()

SC::TestCase::TestCase ( TestReport report,
StringView  testName 
)

Adds this TestCase to a TestReport with a name.

Parameters
reportThe current TestReport
testNameName of this TestCase

Member Function Documentation

◆ recordExpectation() [1/2]

bool SC::TestCase::recordExpectation ( StringView  expression,
bool  status,
StringView  detailedError = StringView() 
)

Records an expectation for a given expression.

Parameters
expressionExpression converted to string
statusThe boolean expectation of a test
detailedErrorA detailed error message
Returns
status

◆ recordExpectation() [2/2]

bool SC::TestCase::recordExpectation ( StringView  expression,
Result  status 
)

Records an expectation for a given expression.

Parameters
expressionExpression converted to string
statusA Result object, output from a test
Returns
false if status Result is not valid

◆ test_section()

bool SC::TestCase::test_section ( StringView  sectionName,
Execute  execution = Execute::Default 
)

Starts a new test section.

Parameters
sectionNameThe name of the section
executionExecution criteria
Returns
true if the test is enabled, false otherwise

Member Data Documentation

◆ report

TestReport& SC::TestCase::report

The TestReport object passed in the constructor.


The documentation for this struct was generated from the following file: