Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

* Added unit test to JSON unicode change

  • Loading branch information...
commit 92ba6563f06d5efacb44c4ac0aa35e44b5cf3ceb 1 parent 3a21162
Rangel Reale authored December 28, 2012
30  JSON/testsuite/src/JSONTest.cpp
@@ -859,6 +859,35 @@ void JSONTest::testTemplate()
859 859
 }
860 860
 
861 861
 
  862
+void JSONTest::testUnicode()
  863
+{
  864
+	const unsigned char supp[] = {0x61, 0xE1, 0xE9, 0x78, 0xED, 0xF3, 0xFA, 0x0};
  865
+	std::string text((const char*) supp);
  866
+
  867
+	std::string json = "{ \"test\" : \"a\u00E1\u00E9x\u00ED\u00F3\u00FA\" }";
  868
+	Parser parser;
  869
+
  870
+	Var result;
  871
+	try
  872
+	{
  873
+		DefaultHandler handler;
  874
+		parser.setHandler(&handler);
  875
+		parser.parse(json);
  876
+		result = handler.result();
  877
+	}
  878
+	catch(JSONException& jsone)
  879
+	{
  880
+		std::cout << jsone.message() << std::endl;
  881
+		assert(false);
  882
+	}
  883
+	assert(result.type() == typeid(Object::Ptr));
  884
+
  885
+	Object::Ptr object = result.extract<Object::Ptr>();
  886
+	Var test = object->get("test");
  887
+	assert(test.convert<std::string>() == text);
  888
+}
  889
+
  890
+
862 891
 std::string JSONTest::getTestFilesPath(const std::string& type)
863 892
 {
864 893
 	std::ostringstream ostr;
@@ -918,6 +947,7 @@ CppUnit::Test* JSONTest::suite()
918 947
 	CppUnit_addTest(pSuite, JSONTest, testValidJanssonFiles);
919 948
 	CppUnit_addTest(pSuite, JSONTest, testInvalidJanssonFiles);
920 949
 	CppUnit_addTest(pSuite, JSONTest, testTemplate);
  950
+	CppUnit_addTest(pSuite, JSONTest, testUnicode);
921 951
 
922 952
 	return pSuite;
923 953
 }
1  JSON/testsuite/src/JSONTest.h
@@ -76,6 +76,7 @@ class JSONTest: public CppUnit::TestCase
76 76
 	void testInvalidJanssonFiles();
77 77
 	void testTemplate();
78 78
 	void testItunes();
  79
+	void testUnicode();
79 80
 
80 81
 	void setUp();
81 82
 	void tearDown();

0 notes on commit 92ba656

Please sign in to comment.
Something went wrong with that request. Please try again.