Skip to content

Commit

Permalink
* Added unit test to JSON unicode change
Browse files Browse the repository at this point in the history
  • Loading branch information
RangelReale committed Dec 28, 2012
1 parent 3a21162 commit 92ba656
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
30 changes: 30 additions & 0 deletions JSON/testsuite/src/JSONTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -859,6 +859,35 @@ void JSONTest::testTemplate()
}


void JSONTest::testUnicode()
{
const unsigned char supp[] = {0x61, 0xE1, 0xE9, 0x78, 0xED, 0xF3, 0xFA, 0x0};
std::string text((const char*) supp);

std::string json = "{ \"test\" : \"a\u00E1\u00E9x\u00ED\u00F3\u00FA\" }";
Parser parser;

Var result;
try
{
DefaultHandler handler;
parser.setHandler(&handler);
parser.parse(json);
result = handler.result();
}
catch(JSONException& jsone)
{
std::cout << jsone.message() << std::endl;
assert(false);
}
assert(result.type() == typeid(Object::Ptr));

Object::Ptr object = result.extract<Object::Ptr>();
Var test = object->get("test");
assert(test.convert<std::string>() == text);
}


std::string JSONTest::getTestFilesPath(const std::string& type)
{
std::ostringstream ostr;
Expand Down Expand Up @@ -918,6 +947,7 @@ CppUnit::Test* JSONTest::suite()
CppUnit_addTest(pSuite, JSONTest, testValidJanssonFiles);
CppUnit_addTest(pSuite, JSONTest, testInvalidJanssonFiles);
CppUnit_addTest(pSuite, JSONTest, testTemplate);
CppUnit_addTest(pSuite, JSONTest, testUnicode);

return pSuite;
}
1 change: 1 addition & 0 deletions JSON/testsuite/src/JSONTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ class JSONTest: public CppUnit::TestCase
void testInvalidJanssonFiles();
void testTemplate();
void testItunes();
void testUnicode();

void setUp();
void tearDown();
Expand Down

0 comments on commit 92ba656

Please sign in to comment.