diff --git a/test/test_table_view.cpp b/test/test_table_view.cpp index f1b92e48624..88935c2d98c 100644 --- a/test/test_table_view.cpp +++ b/test/test_table_view.cpp @@ -1,5 +1,7 @@ #include #include +#include +#include using namespace tightdb; @@ -13,6 +15,27 @@ TIGHTDB_TABLE_2(TestTableDate, } +TEST(TableViewJSON) +{ + Table table; + table.add_column(type_Int, "first"); + + size_t ndx = table.add_empty_row(); + table.set_int(0, ndx, 1); + ndx = table.add_empty_row(); + table.set_int(0, ndx, 2); + ndx = table.add_empty_row(); + table.set_int(0, ndx, 3); + + TableView v = table.where().find_all(1); + std::stringstream ss; + v.to_json(ss); + const std::string json = ss.str(); + CHECK_EQUAL(true, json.length() > 0); + CHECK_EQUAL("[{\"first\":2},{\"first\":3}]", json); +} + + TEST(TableViewDateMaxMin) { TestTableDate ttd; diff --git a/test/testgroup.cpp b/test/testgroup.cpp index 6ddf615092a..12760f43ea4 100644 --- a/test/testgroup.cpp +++ b/test/testgroup.cpp @@ -891,6 +891,7 @@ TEST(Group_toJSON) g.to_json(ss); const std::string str = ss.str(); CHECK(str.length() > 0); + CHECK_EQUAL("{\"test\":[{\"first\":\"jeff\",\"second\":1,\"third\":true,\"fourth\":2},{\"first\":\"jim\",\"second\":1,\"third\":true,\"fourth\":2}]}", str); } TEST(Group_toString) diff --git a/test/testtable.cpp b/test/testtable.cpp index 0afaf0ca07d..689fd4b14d7 100644 --- a/test/testtable.cpp +++ b/test/testtable.cpp @@ -555,7 +555,8 @@ TEST(Table_test_json_simple) s.add_column(type_Int, "int"); s.add_column(type_Bool, "bool"); s.add_column(type_Date, "date"); - // FIXME: Add float, double + s.add_column(type_Float, "float"); + s.add_column(type_Double, "double"); s.add_column(type_String, "string"); s.add_column(type_Binary, "binary"); table.update_from_spec(); @@ -563,11 +564,13 @@ TEST(Table_test_json_simple) // Add some rows for (size_t i = 0; i < 1; ++i) { table.insert_int(0, i, i); - table.insert_bool(1, i, (i % 2 ? true : false)); + table.insert_bool(1, i, (i % 2 == 0? true : false)); table.insert_date(2, i, 0x7fffeeeeL); - table.insert_string(3, i, "helloooooo"); + table.insert_float(3, i, 3.14); + table.insert_double(4, i, 2.71); + table.insert_string(5, i, "helloooooo"); const char bin[] = "123456789012345678901234567890nopq"; - table.insert_binary(4, i, BinaryData(bin, sizeof bin)); + table.insert_binary(6, i, BinaryData(bin, sizeof bin)); table.insert_done(); } @@ -575,7 +578,7 @@ TEST(Table_test_json_simple) table.to_json(ss); const string json = ss.str(); CHECK_EQUAL(true, json.length() > 0); - //cerr << "JSON:" << json << "\n"; + CHECK_EQUAL("[{\"int\":0,\"bool\":true,\"date\":\"2038-01-19 02:01:18\",\"float\":3.1400001e+00,\"double\":2.7100000000000000e+00,\"string\":\"helloooooo\",\"binary\":\"3132333435363738393031323334353637383930313233343536373839306e6f707100\"}]", json); }