diff --git a/src/GTMesh/Debug/Printers/PrintExportable.h b/src/GTMesh/Debug/Printers/PrintExportable.h index 7a88d506ab7f653c414c0a5aaa3ed48de54c3ca6..059f8c77acb3f94e9542043102cd0fb0380a9876 100644 --- a/src/GTMesh/Debug/Printers/PrintExportable.h +++ b/src/GTMesh/Debug/Printers/PrintExportable.h @@ -1,7 +1,7 @@ #ifndef PRINTEXPORTABLE_H #define PRINTEXPORTABLE_H #include <type_traits> -#include <GTMesh/Traits/CustomTypeTraits.h> +#include "../VariableExport.h" struct PrintExportable { static int print(...) {return 0;} @@ -16,7 +16,6 @@ struct PrintExportable { ost << var; } - template <typename T> static void print(std::ostream& ost, const bool& var, ...) { ost << (var == true ? "true" : "false"); } diff --git a/src/UnitTests/Debug/DBGVAR_JSONTest.cpp b/src/UnitTests/Debug/DBGVAR_JSONTest.cpp index fca1371d4f6c740facc4de173abcfde539080a79..06e15c82ffc10237a2c1a871b29a23c6b1794f32 100644 --- a/src/UnitTests/Debug/DBGVAR_JSONTest.cpp +++ b/src/UnitTests/Debug/DBGVAR_JSONTest.cpp @@ -8,143 +8,142 @@ #include "GTMesh/Debug/Debug.h" #include <fstream> std::string expectedRes = -R"({ -"logs":[ - { - "gInd" : 0, - "file" : "..\\TemplateTest\\main.cpp", - "line" : 158, - "expr" : "b", - "data" : false - }, - { - "gInd" : 0, - "file" : "..\\TemplateTest\\main.cpp", - "line" : 158, - "expr" : "vec", - "data" : [ [ 1, 2, 3 ], [ 1, 2, 3 ], [ 1, 2, 3 ], [ 1, 2, 3 ], [ 1, 2, 3 ] ] - }, - { - "gInd" : 1, - "file" : "..\\TemplateTest\\main.cpp", - "line" : 160, - "expr" : "!b", - "data" : true - }, - { - "gInd" : 1, - "file" : "..\\TemplateTest\\main.cpp", - "line" : 160, - "expr" : "vec[0]", - "data" : [ 1, 2, 3 ] - }, - { - "gInd" : 2, - "file" : "..\\TemplateTest\\main.cpp", - "line" : 162, - "expr" : "r", - "data" : 42.15 - }, - { - "gInd" : 2, - "file" : "..\\TemplateTest\\main.cpp", - "line" : 162, - "expr" : "i", - "data" : 15 - }, - { - "gInd" : 2, - "file" : "..\\TemplateTest\\main.cpp", - "line" : 162, - "expr" : "c", - "data" : "*" - }, - { - "gInd" : 2, - "file" : "..\\TemplateTest\\main.cpp", - "line" : 162, - "expr" : "list", - "data" : [ 1, 2, 3 ] - }, - { - "gInd" : 2, - "file" : "..\\TemplateTest\\main.cpp", - "line" : 162, - "expr" : "vec", - "data" : [ [ 1, 2, 3 ], [ 1, 2, 3 ], [ 1, 2, 3 ], [ 1, 2, 3 ], [ 1, 2, 3 ] ] - }, - { - "gInd" : 2, - "file" : "..\\TemplateTest\\main.cpp", - "line" : 162, - "expr" : "b", - "data" : false - }, - { - "gInd" : 2, - "file" : "..\\TemplateTest\\main.cpp", - "line" : 162, - "expr" : "m", - "data" : [ { "druhy": 2}, { "prvni": 1}, { "treti": 3} ] - }, - { - "gInd" : 3, - "file" : "..\\TemplateTest\\main.cpp", - "line" : 164, - "expr" : "r+1", - "data" : 43.15 - }, - { - "gInd" : 3, - "file" : "..\\TemplateTest\\main.cpp", - "line" : 164, - "expr" : "i+1", - "data" : 16 - }, - { - "gInd" : 3, - "file" : "..\\TemplateTest\\main.cpp", - "line" : 164, - "expr" : "char(c+1)\", - "data" : "+" - }, - { - "gInd" : 3, - "file" : "..\\TemplateTest\\main.cpp", - "line" : 164, - "expr" : "list", - "data" : [ 1, 2, 3 ] - }, - { - "gInd" : 3, - "file" : "..\\TemplateTest\\main.cpp", - "line" : 164, - "expr" : "vec[0]", - "data" : [ 1, 2, 3 ] - }, - { - "gInd" : 3, - "file" : "..\\TemplateTest\\main.cpp", - "line" : 164, - "expr" : "b", - "data" : false - }, - { - "gInd" : 3, - "file" : "..\\TemplateTest\\main.cpp", - "line" : 164, - "expr" : "m[\"prvni\"]", - "data" : 1 - } -] -})"; +"{\n\ +\"logs\":[\n\ +\t{\n\ +\t\t\"gInd\" : 0,\n\ +\t\t\"file\" : \"__FILE__\",\n\ +\t\t\"line\" : 158,\n\ +\t\t\"expr\" : \"b\",\n\ +\t\t\"data\" : false\n\ +\t},\n\ +\t{\n\ +\t\t\"gInd\" : 0,\n\ +\t\t\"file\" : \"__FILE__\",\n\ +\t\t\"line\" : 158,\n\ +\t\t\"expr\" : \"vec\",\n\ +\t\t\"data\" : [ [ 1, 2, 3 ], [ 1, 2, 3 ], [ 1, 2, 3 ], [ 1, 2, 3 ], [ 1, 2, 3 ] ]\n\ +\t},\n\ +\t{\n\ +\t\t\"gInd\" : 1,\n\ +\t\t\"file\" : \"__FILE__\",\n\ +\t\t\"line\" : 160,\n\ +\t\t\"expr\" : \"!b\",\n\ +\t\t\"data\" : true\n\ +\t},\n\ +\t{\n\ +\t\t\"gInd\" : 1,\n\ +\t\t\"file\" : \"__FILE__\",\n\ +\t\t\"line\" : 160,\n\ +\t\t\"expr\" : \"vec[0]\",\n\ +\t\t\"data\" : [ 1, 2, 3 ]\n\ +\t},\n\ +\t{\n\ +\t\t\"gInd\" : 2,\n\ +\t\t\"file\" : \"__FILE__\",\n\ +\t\t\"line\" : 162,\n\ +\t\t\"expr\" : \"r\",\n\ +\t\t\"data\" : 42.15\n\ +\t},\n\ +\t{\n\ +\t\t\"gInd\" : 2,\n\ +\t\t\"file\" : \"__FILE__\",\n\ +\t\t\"line\" : 162,\n\ +\t\t\"expr\" : \"i\",\n\ +\t\t\"data\" : 15\n\ +\t},\n\ +\t{\n\ +\t\t\"gInd\" : 2,\n\ +\t\t\"file\" : \"__FILE__\",\n\ +\t\t\"line\" : 162,\n\ +\t\t\"expr\" : \"c\",\n\ +\t\t\"data\" : \"*\"\n\ +\t},\n\ +\t{\n\ +\t\t\"gInd\" : 2,\n\ +\t\t\"file\" : \"__FILE__\",\n\ +\t\t\"line\" : 162,\n\ +\t\t\"expr\" : \"list\",\n\ +\t\t\"data\" : [ 1, 2, 3 ]\n\ +\t},\n\ +\t{\n\ +\t\t\"gInd\" : 2,\n\ +\t\t\"file\" : \"__FILE__\",\n\ +\t\t\"line\" : 162,\n\ +\t\t\"expr\" : \"vec\",\n\ +\t\t\"data\" : [ [ 1, 2, 3 ], [ 1, 2, 3 ], [ 1, 2, 3 ], [ 1, 2, 3 ], [ 1, 2, 3 ] ]\n\ +\t},\n\ +\t{\n\ +\t\t\"gInd\" : 2,\n\ +\t\t\"file\" : \"__FILE__\",\n\ +\t\t\"line\" : 162,\n\ +\t\t\"expr\" : \"b\",\n\ +\t\t\"data\" : false\n\ +\t},\n\ +\t{\n\ +\t\t\"gInd\" : 2,\n\ +\t\t\"file\" : \"__FILE__\",\n\ +\t\t\"line\" : 162,\n\ +\t\t\"expr\" : \"m\",\n\ +\t\t\"data\" : [ { \"druhy\": 2}, { \"prvni\": 1}, { \"treti\": 3} ]\n\ +\t},\n\ +\t{\n\ +\t\t\"gInd\" : 3,\n\ +\t\t\"file\" : \"__FILE__\",\n\ +\t\t\"line\" : 164,\n\ +\t\t\"expr\" : \"r+1\",\n\ +\t\t\"data\" : 43.15\n\ +\t},\n\ +\t{\n\ +\t\t\"gInd\" : 3,\n\ +\t\t\"file\" : \"__FILE__\",\n\ +\t\t\"line\" : 164,\n\ +\t\t\"expr\" : \"i+1\",\n\ +\t\t\"data\" : 16\n\ +\t},\n\ +\t{\n\ +\t\t\"gInd\" : 3,\n\ +\t\t\"file\" : \"__FILE__\",\n\ +\t\t\"line\" : 164,\n\ +\t\t\"expr\" : \"char(c+1)\",\n\ +\t\t\"data\" : \"+\"\n\ +\t},\n\ +\t{\n\ +\t\t\"gInd\" : 3,\n\ +\t\t\"file\" : \"__FILE__\",\n\ +\t\t\"line\" : 164,\n\ +\t\t\"expr\" : \"list\",\n\ +\t\t\"data\" : [ 1, 2, 3 ]\n\ +\t},\n\ +\t{\n\ +\t\t\"gInd\" : 3,\n\ +\t\t\"file\" : \"__FILE__\",\n\ +\t\t\"line\" : 164,\n\ +\t\t\"expr\" : \"vec[0]\",\n\ +\t\t\"data\" : [ 1, 2, 3 ]\n\ +\t},\n\ +\t{\n\ +\t\t\"gInd\" : 3,\n\ +\t\t\"file\" : \"__FILE__\",\n\ +\t\t\"line\" : 164,\n\ +\t\t\"expr\" : \"b\",\n\ +\t\t\"data\" : false\n\ +\t},\n\ +\t{\n\ +\t\t\"gInd\" : 3,\n\ +\t\t\"file\" : \"__FILE__\",\n\ +\t\t\"line\" : 164,\n\ +\t\t\"expr\" : \"m[\\\"prvni\\\"]\",\n\ +\t\t\"data\" : 1\n\ +\t}\n\ +]\n\ +}"; TEST( DBGVAR_JSONTest, basicTest ) { double r = 42.15; int i = 15; char c = 42; bool b = false; - std::stringstream ss; std::list<int> list = {1,2,3}; @@ -154,21 +153,23 @@ TEST( DBGVAR_JSONTest, basicTest ) {"druhy", 2}, {"treti", 3} }; - - DBGVAR_JSON(b, vec); + { + JSONLogger jlog("jlog.json"); + jlog.writeVar(__LINE__, "__FILE__", "b", b, "vec", vec); + + jlog.writeVar(__LINE__, "__FILE__", "!b", !b, "vec[0]", vec[0]); - DBGVAR_JSON(!b, vec[0]); + jlog.writeVar(__LINE__, "__FILE__", "r", r, "i", i, "c", c, "list", list, "vec", vec, "b", b, "m", m); - DBGVAR_JSON(r, i, c, list, vec, b, m); + jlog.writeVar(__LINE__, "__FILE__", "r+1", r+1, "i+1", i+1, "char(c+1)", char(c+1), "list", list, "vec[0]", vec[0], "b", b, "m[\"prvni\"]", m["prvni"]); + } // destroy jlog - DBGVAR_JSON(r+1, i+1, char(c+1), list, vec[0], b, m["prvni"]); - - std::ifstream ifs("DBG.json"); + std::ifstream ifs("jlog.json"); EXPECT_TRUE(ifs.is_open()); - - std::string str((std::istreambuf_iterator<char>(ifs)), + + std::string str((std::istreambuf_iterator<char>(ifs)), std::istreambuf_iterator<char>()); - //EXPECT_EQ(str, expectedRes); + EXPECT_EQ(str, expectedRes); } #endif