#include <iostream>
#include <j/cppunit/cppunit.hpp>
#include <j/cppunit/assert.hpp>
#include <j/lang/assertion_error.hpp>
#include <j/lang/errno.hpp>
using namespace j;
using namespace j::lang;
using namespace j::cppunit;
class AssertionErrorTest : public TestCase
{
public:
AssertionErrorTest() {}
~AssertionErrorTest() {}
void setUp() {}
void tearDown() {}
void testAssertionError()
{
AssertionError e;
String exp = j::lang::Errno::message(j::lang::Errno::get());
String act = e.getMessage();
assertEquals(exp, act);
assertEquals("", e.getFile());
assertEquals("", e.getFunc());
assertEquals(0, e.getLine());
}
void testAssertionErrorMsg()
{
String msg = "ERROR MESSAGE";
AssertionError e(msg);
assertEquals(msg, e.getMessage());
assertEquals("", e.getFile());
assertEquals("", e.getFunc());
assertEquals(0, e.getLine());
}
void testAssertionErrorMsgFileFuncLine()
{
String msg = "ERROR MESSAGE 2";
const char *file = __FILE__;
const char *func = __func__;
int line = __LINE__;
AssertionError e(msg, file, func, line);
assertEquals(msg, e.getMessage());
assertEquals(file, e.getFile());
assertEquals(func, e.getFunc());
assertEquals(line, e.getLine());
}
void testAssertionErrorCopy()
{
String msg = "ERROR MESSAGE 2";
const char *file = __FILE__;
const char *func = __func__;
int line = __LINE__;
AssertionError e(msg, file, func, line);
AssertionError ee = e;
assertEquals(msg, e.getMessage());
assertEquals(file, e.getFile());
assertEquals(func, e.getFunc());
assertEquals(line, e.getLine());
assertEquals(msg, ee.getMessage());
assertEquals(file, ee.getFile());
assertEquals(func, ee.getFunc());
assertEquals(line, ee.getLine());
assertTrue(e != ee);
assertFalse(e == ee);
}
void testAssertionErrorMove()
{
String msg = "ERROR MESSAGE 3";
const char *file = __FILE__;
const char *func = __func__;
int line = __LINE__;
AssertionError e(msg, file, func, line);
AssertionError ee = std::move(e);
assertEquals(msg, ee.getMessage());
assertEquals(file, ee.getFile());
assertEquals(func, ee.getFunc());
assertEquals(line, ee.getLine());
}
void testAssertionErrorToString()
{
String msg = "ERROR MESSAGE 3";
const char *file = "SampleFile";
const char *func = "SampleFunction";
int line = 123;
const char *exp = "AssertionError: ERROR MESSAGE 3\n\tat SampleFile:123 [SampleFunction]";
AssertionError e(msg, file, func, line);
assertEquals(exp, e.toString());
}
void suite()
{
RUN_TEST("new AssertionError()", testAssertionError);
RUN_TEST("new AssertionError(msg)", testAssertionErrorMsg);
RUN_TEST("new AssertionError(msg, ...)", testAssertionErrorMsgFileFuncLine);
RUN_TEST("copy", testAssertionErrorCopy);
RUN_TEST("move", testAssertionErrorMove);
RUN_TEST("toString()", testAssertionErrorToString);
}
};