Permalink
Browse files

* Added unit test to JSON unicode change

  • Loading branch information...
1 parent 3a21162 commit 92ba6563f06d5efacb44c4ac0aa35e44b5cf3ceb @RangelReale committed Dec 28, 2012
Showing with 31 additions and 0 deletions.
  1. +30 −0 JSON/testsuite/src/JSONTest.cpp
  2. +1 −0 JSON/testsuite/src/JSONTest.h
@@ -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;
@@ -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;
}
@@ -76,6 +76,7 @@ class JSONTest: public CppUnit::TestCase
void testInvalidJanssonFiles();
void testTemplate();
void testItunes();
+ void testUnicode();
void setUp();
void tearDown();

0 comments on commit 92ba656

Please sign in to comment.