| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 | #include <iostream>
#include <string.h>
#include <gtest/gtest.h>
#include "DBO/Result.h"
template <class T>
void testStream(const T& data, const std::string& ref) {
    std::ostringstream stream;
    stream << data;
    ASSERT_EQ(stream.str(), ref);
}
TEST(Result, ok)
{
    testStream(ResultInt::ok(42), "Success: 42");
    testStream(ResultInt::ok(0), "Success: 0");
    testStream(ResultBool::ok(true), "Success: 1");
    testStream(ResultBool::ok(false), "Success: 0");
    testStream(ResultDouble::ok(0.42), "Success: 0.42");
    testStream(ResultDouble::ok(-0.42), "Success: -0.42");
}
TEST(Result, error)
{
    testStream(ResultInt::error("My error label"), "Error: My error label");
    testStream(ResultInt::error(""), "Error: Unknown error");
}
TEST(Result, strerror)
{
    errno = 0;
    testStream(ResultInt::strerror(), "Error: Success");
    errno = EACCES;
    testStream(ResultInt::strerror(), "Error: Permission denied");
    errno = 0;
}
int main(int argc, char* argv[])
{
//    std::cout << IResult::ok(42) << std::endl;
//    std::cout << IResult::error("Test. error") << std::endl;
//    errno = EACCES;
//    std::cout << IResult::strerror() << std::endl;
//    errno = 0;
    ::testing::InitGoogleTest(&argc, argv);
    return RUN_ALL_TESTS();
}
 |