예제 #1
0
bool Config::ParseFile(const wchar_t * wsPath)
{
	JSONSTREAM *stream = json_new_stream(jsonNodeComplete, jsonNodeError, this);
	
	FILE *f = NULL;
	char buffer[256];
	memset(buffer, 0, sizeof(buffer));
	int iResult = _wfopen_s(&f, wsPath, L"rt");
	if (iResult == 0 && f != NULL)
	{
		while (buffer != NULL && !feof(f))
		{
			fgets(buffer, sizeof(buffer), f);
			RemoveComments(buffer);
			json_stream_push(stream, buffer);
		}

		fclose(f);
	}
	// TODO: file not found

	json_delete_stream(stream);

	if (m_wsUrl != std::wstring())
	{
		m_bLoadSuccess = true;
		return true;
	}

	return false;
}
void TestSuite::TestStreams(void){
#ifdef JSON_STREAM
    UnitTest::SetPrefix("TestStreams.cpp - Streams");
    counter = 0;
	errorCounter = 0;

    #ifdef JSON_LIBRARY
	   JSONSTREAM * test = json_new_stream(Callback, errorCallback, (void*)0xDEADBEEF);
	   json_stream_push(test, JSON_TEXT("{}[]"));
	   assertEquals(2, counter);
	   assertEquals(0, errorCounter);
	   json_stream_push(test, JSON_TEXT("{\"hel"));
	   assertEquals(2, counter);
	   assertEquals(0, errorCounter);
	   json_stream_push(test, JSON_TEXT("lo\" : 1"));
	   assertEquals(2, counter);
	   assertEquals(0, errorCounter);
	   json_stream_push(test, JSON_TEXT("}["));
	   assertEquals(3, counter);
	   assertEquals(0, errorCounter);
	   json_stream_push(test, JSON_TEXT("1,2,3]{\"hi\" : { \"one\" : 1}"));
	   assertEquals(4, counter);
	   assertEquals(0, errorCounter);
	   json_stream_push(test, JSON_TEXT("}"));
	   assertEquals(5, counter);
	   assertEquals(0, errorCounter);
	
		#ifdef JSON_SAFE
			json_stream_push(test, JSON_TEXT("{\"hello\":12keaueuataueaouhe"));
			assertEquals(1, errorCounter);
		#endif
	   json_delete_stream(test);
    #else
	   JSONStream test(Callback, errorCallback, (void*)0xDEADBEEF);
	   test << JSON_TEXT("{}[]");
	   assertEquals(2, counter);
	   assertEquals(0, errorCounter);
	   test << JSON_TEXT("{\"hel");
	   assertEquals(2, counter);
	   assertEquals(0, errorCounter);
	   test << JSON_TEXT("lo\" : 1");
	   assertEquals(2, counter);
	   assertEquals(0, errorCounter);
	   test << JSON_TEXT("}[");
	   assertEquals(3, counter);
	   assertEquals(0, errorCounter);
	   test << JSON_TEXT("1,2,3]{\"hi\" : { \"one\" : 1}");
	   assertEquals(4, counter);
	   assertEquals(0, errorCounter);
	   test << JSON_TEXT("}");
	   assertEquals(5, counter);
	   assertEquals(0, errorCounter);
	
		#ifdef JSON_SAFE
			test << JSON_TEXT("{\"hello\":12keaueuataueaouhe");
			assertEquals(1, errorCounter);
		#endif
	
		#ifdef JSON_SECURITY_MAX_STREAM_OBJECTS
			test.reset();
			unsigned int currentCount = errorCounter;
			json_string safe;
			for(int i = 0; i < JSON_SECURITY_MAX_STREAM_OBJECTS; ++i){
				safe += JSON_TEXT("{}");
			}
			test << safe;
			assertEquals(133, counter);
			assertEquals(currentCount, errorCounter);
	
			test.reset();
			json_string unsafe;
			for(int i = 0; i <= JSON_SECURITY_MAX_STREAM_OBJECTS + 1; ++i){
				unsafe += JSON_TEXT("{}");
			}
			test << unsafe;
			assertEquals(261, counter);
			assertEquals(currentCount + 1, errorCounter);
		#endif
    #endif
#endif
}