Skip to content

Commit

Permalink
Merge pull request #129 from kneth/extend-json-unittests
Browse files Browse the repository at this point in the history
Extend json unittests
  • Loading branch information
Kenneth Geisshirt committed Aug 21, 2013
2 parents 85061d4 + b5ca729 commit 6cd469e
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 5 deletions.
23 changes: 23 additions & 0 deletions test/test_table_view.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include <UnitTest++.h>
#include <tightdb/table_macros.hpp>
#include <string>
#include <sstream>

using namespace tightdb;

Expand All @@ -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;
Expand Down
1 change: 1 addition & 0 deletions test/testgroup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
13 changes: 8 additions & 5 deletions test/testtable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -555,27 +555,30 @@ 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();

// 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();
}

stringstream ss;
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);
}


Expand Down

0 comments on commit 6cd469e

Please sign in to comment.