Newer
Older
libj / modules / j / base / test / src / ut_runtime_exception.cpp
#include <iostream>
#include <j/cppunit/cppunit.hpp>
#include <j/cppunit/assert.hpp>
#include <j/lang/runtime_exception.hpp>
#include <j/lang/errno.hpp>

using namespace j;
using namespace j::lang;
using namespace j::cppunit;

class RuntimeExceptionTest : public TestCase
{
public:
    RuntimeExceptionTest() {}
    ~RuntimeExceptionTest() {}
    void setUp() {}
    void tearDown() {}

    void testRuntimeException()
    {
        RuntimeException e;
        String exp = j::lang::Errno::message(j::lang::Errno::get());
        String act = e.getMessage();
        assertEquals(exp, act);
    }

    void testRuntimeExceptionMsg()
    {
        String msg = "ERROR MESSAGE";
        RuntimeException e(msg);
        assertEquals(msg, e.getMessage());
    }

    void testRuntimeExceptionCopy()
    {
        String msg = "ERROR MESSAGE 2";

        RuntimeException e(msg);
        RuntimeException ee = e;
        assertEquals(msg, e.getMessage());
        assertTrue(e != ee);
        assertFalse(e == ee);
    }

    void testRuntimeExceptionMove()
    {
        String msg = "ERROR MESSAGE 3";

        RuntimeException e(msg);
        RuntimeException ee = std::move(e);
        assertEquals(msg, ee.getMessage());
    }

    void testRuntimeExceptionToString()
    {
        String msg = "ERROR MESSAGE 3";
        RuntimeException e(msg);
        assertEquals(msg, e.toString());
    }

    void suite()
    {
        RUN_TEST("new RuntimeException()", testRuntimeException);
        RUN_TEST("new RuntimeException(msg)", testRuntimeExceptionMsg);
        RUN_TEST("copy", testRuntimeExceptionCopy);
        RUN_TEST("move", testRuntimeExceptionMove);
        RUN_TEST("toString()", testRuntimeExceptionToString);
    }
};