Esempio n. 1
0
void CSteamProto::OnGotHistoryMessages(const HttpResponse *response, void *arg)
{
	MCONTACT hContact = FindContact((char*)arg);
	if (!hContact)
		return;

	if (!ResponseHttpOk(response))
		return;

	JSONROOT root(response->pData);
	if (root == NULL)
		return;

	JSONNode *node = json_get(root, "response");

	JSONNode *messages = json_get(node, "messages");
	JSONNode *nmessages = json_as_array(messages);

	// Self SteamID
	ptrA steamId(getStringA("SteamID"));

	for (size_t i = json_size(nmessages); i > 0; i--)
	{
		JSONNode *message = json_at(nmessages, i - 1);

		node = json_get(message, "accountid");
		const char *authorSteamId = AccountIdToSteamId(_ttoi64(ptrT(json_as_string(node))));

		node = json_get(message, "message");
		ptrT text(json_as_string(node));
		T2Utf szMessage(text);

		node = json_get(message, "timestamp");
		time_t timestamp = _ttoi64(ptrT(json_as_string(node)));

		// Ignore already existing messages
		if (timestamp <= m_lastMessageTS)
			continue;

		PROTORECVEVENT recv = { 0 };
		recv.timestamp = timestamp;
		recv.szMessage = szMessage;

		if (strcmp(steamId, authorSteamId))
		{
			// Received message
			ProtoChainRecvMsg(hContact, &recv);
		}
		else
		{
			// Sent message
			recv.flags = PREF_SENT;
			Proto_RecvMessage(hContact, &recv);
		}
	}

	json_delete(nmessages);
}
Esempio n. 2
0
void CSteamProto::OnGotConversations(const HttpResponse *response)
{
	// Don't load any messages when we don't have lastMessageTS, as it may cause duplicates
	if (m_lastMessageTS <= 0)
		return;

	if (!ResponseHttpOk(response))
		return;

	JSONROOT root(response->pData);
	if (root == NULL)
		return;

	JSONNode *node = json_get(root, "response");
	JSONNode *sessions = json_get(node, "message_sessions");
	JSONNode *nsessions = json_as_array(sessions);

	if (nsessions != NULL)
	{
		ptrA token(getStringA("TokenSecret"));
		ptrA steamId(getStringA("SteamID"));
		

		for (size_t i = 0; i < json_size(nsessions); i++)
		{
			JSONNode *session = json_at(nsessions, i);

			node = json_get(session, "accountid_friend");
			const char *who = AccountIdToSteamId(_ttoi64(ptrT(json_as_string(node))));

			node = json_get(session, "last_message");
			time_t lastMessageTS = _ttoi64(ptrT(json_as_string(node)));

			/*node = json_get(session, "last_view");
			time_t last_view = _ttoi64(ptrT(json_as_string(node)));

			node = json_get(session, "unread_message_count");
			long unread_count = json_as_int(node);*/

			if (lastMessageTS > m_lastMessageTS)
			{
				PushRequest(
					new GetHistoryMessagesRequest(token, steamId, who, m_lastMessageTS),
					&CSteamProto::OnGotHistoryMessages,
					mir_strdup(who),
					MirFreeArg);
			}
		}

		json_delete(nsessions);
	}
}
Esempio n. 3
0
JSON *json_get_array(JSON *j, const char *name) {
	JSON *v = json_get_member(j, name);
	if(v) 
		return json_as_array(v);
	return NULL;
}
Esempio n. 4
0
void CSteamProto::PollingThread(void*)
{
	debugLog(_T("CSteamProto::PollingThread: entering"));

	ptrA token(getStringA("TokenSecret"));
	ptrA umqId(getStringA("UMQID"));
	UINT32 messageId = getDword("MessageID", 0);

	//PollApi::PollResult pollResult;
	int errors = 0;
	bool breaked = false;
	while (!isTerminated && !breaked && errors < POLLING_ERRORS_LIMIT)
	{
		PollRequest *request = new PollRequest(token, umqId, messageId, IdleSeconds());
		//request->nlc = m_pollingConnection;
		HttpResponse *response = request->Send(m_hNetlibUser);
		delete request;

		if (response == NULL || response->resultCode != HTTP_CODE_OK)
		{
			if (response != NULL)
				delete response;

			errors++;
			continue;
		}
		else
			errors = 0;

		JSONROOT root(response->pData);
		JSONNode *node = json_get(root, "error");
		ptrT error(json_as_string(node));

		if (!lstrcmpi(error, _T("OK")))
		{
			node = json_get(root, "messagelast");
			messageId = json_as_int(node);

			node = json_get(root, "messages");
			JSONNode *nroot = json_as_array(node);

			if (nroot != NULL)
			{
				ParsePollData(nroot);
				json_delete(nroot);
			}

			m_pollingConnection = response->nlc;
		}
		else if (!lstrcmpi(error, _T("Timeout")))
		{
			continue;
		}
		/*else if (!lstrcmpi(error, _T("Not Logged On"))) // 'else' below will handle this error, we don't need this particular check right now
		{
			if (!IsOnline())
			{
				// need to relogin
				debugLog(_T("CSteamProto::PollingThread: not logged on"));

				SetStatus(ID_STATUS_OFFLINE);
			}

			breaked = true;
		}*/
		else
		{
			// something wrong
			debugLog(_T("CSteamProto::PollingThread: %s (%d)"), error, response->resultCode);

			// token has expired
			if (response->resultCode == HTTP_CODE_UNAUTHORIZED)
				delSetting("TokenSecret");

			// too low timeout?
			node = json_get(root, "sectimeout");
			int timeout = json_as_int(node);
			if (timeout < STEAM_API_TIMEOUT)
				debugLog(_T("CSteamProto::PollingThread: Timeout is too low (%d)"), timeout);

			breaked = true;
		}

		delete response;
	}

	setDword("MessageID", messageId);

	m_hPollingThread = NULL;
	debugLog(_T("CSteamProto::PollingThread: leaving"));

	if (!isTerminated)
	{
		debugLog(_T("CSteamProto::PollingThread: unexpected termination; switching protocol to offline"));
		SetStatus(ID_STATUS_OFFLINE);
	}
}
Esempio n. 5
0
void CVkProto::OnReceiveChatInfo(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pReq)
{
	debugLogA("CVkProto::OnReceiveChatInfo %d", reply->resultCode);
	if (reply->resultCode != 200)
		return;

	JSONROOT pRoot;
	JSONNODE *pResponse = CheckJsonResponse(pReq, reply, pRoot);
	if (pResponse == NULL)
		return;

	CVkChatInfo *cc = (CVkChatInfo*)pReq->pUserInfo;
	if (m_chats.indexOf(cc) == -1)
		return;

	JSONNODE *info = json_get(pResponse, "info");
	if (info != NULL) {
		ptrT tszTitle(json_as_string(json_get(info, "title")));
		if (lstrcmp(tszTitle, cc->m_tszTopic)) {
			cc->m_tszTopic = mir_tstrdup(tszTitle);
			setTString(cc->m_hContact, "Nick", tszTitle);

			GCDEST gcd = { m_szModuleName, cc->m_tszId, GC_EVENT_CHANGESESSIONAME };
			GCEVENT gce = { sizeof(GCEVENT), &gcd };
			gce.ptszText = tszTitle;
			CallServiceSync(MS_GC_EVENT, 0, (LPARAM)&gce);
		}
		
		cc->m_admin_id = json_as_int(json_get(info, "admin_id"));
	}

	JSONNODE *users = json_as_array(json_get(pResponse, "users"));
	if (users != NULL) {
		for (int i = 0; i < cc->m_users.getCount(); i++)
			cc->m_users[i].m_bDel = true;

		for (int i = 0;; i++) {
			JSONNODE *pUser = json_at(users, i);
			if (pUser == NULL)
				break;

			int uid = json_as_int(json_get(pUser, "uid"));
			TCHAR tszId[20];
			_itot(uid, tszId, 10);

			bool bNew;
			CVkChatUser *cu = cc->m_users.find((CVkChatUser*)&uid);
			if (cu == NULL) {
				cc->m_users.insert(cu = new CVkChatUser(uid));
				bNew = true;
			}
			else bNew = cu->m_bUnknown;
			cu->m_bDel = false;

			ptrT fName(json_as_string(json_get(pUser, "first_name")));
			ptrT lName(json_as_string(json_get(pUser, "last_name")));
			CMString tszNick = CMString(fName).Trim() + _T(" ") + CMString(lName).Trim();
			cu->m_tszNick = mir_tstrdup(tszNick);
			cu->m_bUnknown = false;
			
			if (bNew) {
				GCDEST gcd = { m_szModuleName, cc->m_tszId, GC_EVENT_JOIN };
				GCEVENT gce = { sizeof(GCEVENT), &gcd };
				gce.bIsMe = uid == m_myUserId;
				gce.ptszUID = tszId;
				gce.ptszNick = tszNick;
				gce.ptszStatus = TranslateTS(sttStatuses[uid == cc->m_admin_id]);
				gce.dwItemData = (INT_PTR)cu;
				CallServiceSync(MS_GC_EVENT, 0, (LPARAM)&gce);
			}
		}

		for (int i = cc->m_users.getCount() - 1; i >= 0; i--) {
			CVkChatUser &cu = cc->m_users[i];
			if (!cu.m_bDel)
				continue;

			TCHAR tszId[20];
			_itot(cu.m_uid, tszId, 10);

			GCDEST gcd = { m_szModuleName, cc->m_tszId, GC_EVENT_PART };
			GCEVENT gce = { sizeof(GCEVENT), &gcd };
			gce.ptszUID = tszId;
			CallServiceSync(MS_GC_EVENT, 0, (LPARAM)&gce);

			cc->m_users.remove(i);
		}
	}

	JSONNODE *msgs = json_as_array(json_get(pResponse, "msgs"));
	if (msgs != NULL) {
		for (int i = 1;; i++) {
			JSONNODE *pMsg = json_at(msgs, i);
			if (pMsg == NULL)
				break;

			AppendChatMessage(cc->m_chatid, pMsg, true);
		}
		cc->m_bHistoryRead = true;
	}

	for (int j = 0; j < cc->m_msgs.getCount(); j++) {
		CVkChatMessage &p = cc->m_msgs[j];
		AppendChatMessage(cc, p.m_mid, p.m_uid, p.m_date, p.m_tszBody, p.m_bHistory);
	}
	cc->m_msgs.destroy();
}
Esempio n. 6
0
void CVkProto::OnReceiveMessages(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pReq)
{
	debugLogA("CVkProto::OnReceiveMessages %d", reply->resultCode);
	if (reply->resultCode != 200)
		return;

	JSONROOT pRoot;
	JSONNODE *pResponse = CheckJsonResponse(pReq, reply, pRoot);
	if (pResponse == NULL)
		return;

	JSONNODE *pDlgs = json_as_array(json_get(pResponse, "dlgs"));
	if (pDlgs != NULL) {
		int numDialogs = json_as_int(json_at(pDlgs, 0));
		for (int i = 1; i <= numDialogs; i++) {
			JSONNODE *pDlg = json_at(pDlgs, i);
			if (pDlg == NULL)
				continue;

			int chatid = json_as_int(json_get(pDlg, "chat_id"));
			if (chatid != 0)
			if (m_chats.find((CVkChatInfo*)&chatid) == NULL) {
				AppendChat(chatid, pDlg);
			}
		}
	}

	CMStringA mids, lmids;
	bool bDirectArray = false;

	JSONNODE *pMsgs = json_as_array(json_get(pResponse, "msgs"));
	if (pMsgs == NULL) {
		pMsgs = pResponse;
		bDirectArray = true;
	}

	int numMessages = json_as_int(json_at(pMsgs, 0));
	for (int i = 1; i <= numMessages; i++) {
		JSONNODE *pMsg = json_at(pMsgs, i);
		if (pMsg == NULL)
			continue;

		char szMid[40];
		int mid = json_as_int(json_get(pMsg, "mid"));
		_itoa(mid, szMid, 10);
		if (!mids.IsEmpty())
			mids.AppendChar(',');
		mids.Append(szMid);

		int chat_id = json_as_int(json_get(pMsg, "chat_id"));
		if (chat_id != 0) {
			AppendChatMessage(chat_id, pMsg, false);
			continue;
		}

		// VK documentation lies: even if you specified preview_length=0, 
		// long messages get cut out. So we need to retrieve them from scratch
		ptrT ptszBody(json_as_string(json_get(pMsg, "body")));
		if (!bDirectArray && _tcslen(ptszBody) > 1000) {
			if (!lmids.IsEmpty())
				lmids.AppendChar(',');
			lmids.Append(szMid);
			continue;
		}

		int datetime = json_as_int(json_get(pMsg, "date"));
		int isOut = json_as_int(json_get(pMsg, "out"));
		int uid = json_as_int(json_get(pMsg, "uid"));
		int isRead = json_as_int(json_get(pMsg, "read_state"));

		JSONNODE *pAttachments = json_get(pMsg, "attachments");
		if (pAttachments != NULL)
			ptszBody = mir_tstrdup(CMString(ptszBody) + GetAttachmentDescr(pAttachments));

		MCONTACT hContact = FindUser(uid, true);

		PROTORECVEVENT recv = { 0 };
		recv.flags = PREF_TCHAR;
		if (isRead)
			recv.flags |= PREF_CREATEREAD;
		if (isOut)
			recv.flags |= PREF_SENT;
		recv.timestamp = datetime;
		recv.tszMessage = ptszBody;
		recv.lParam = isOut;
		recv.pCustomData = szMid;
		recv.cbCustomDataSize = (int)strlen(szMid);
		ProtoChainRecvMsg(hContact, &recv);
	}

	MarkMessagesRead(mids);
	RetrieveMessagesByIds(lmids);
}
void TestSuite::TestInspectors(void){
    UnitTest::SetPrefix("TestInspectors.cpp - Inspectors");
    #ifdef JSON_LIBRARY
		  JSONNODE * test = json_new(JSON_NULL);
		  assertEquals(json_type(test), JSON_NULL);
		  json_char * res = json_as_string(test);
		  assertCStringSame(res, JSON_TEXT(""));
		  json_free(res);
		  assertEquals_Primitive(json_as_int(test), 0);
		  assertEquals_Primitive(json_as_float(test), 0.0f);
		  assertEquals(json_as_bool(test), false);

		  json_set_f(test, 15.5f);
		  assertEquals(json_type(test), JSON_NUMBER);
		#ifdef JSON_CASTABLE
		  res = json_as_string(test);
		  assertCStringSame(res, JSON_TEXT("15.5"));
		  json_free(res);
		#endif
		  assertEquals_Primitive(json_as_int(test), 15);
		  assertEquals_Primitive(json_as_float(test), 15.5f);
		  #ifdef JSON_CASTABLE
				assertEquals(json_as_bool(test), true);
		  #endif

		  json_set_f(test, 0.0f);
		  assertEquals(json_type(test), JSON_NUMBER);
		#ifdef JSON_CASTABLE
		  res = json_as_string(test);
		  assertCStringSame(res, JSON_TEXT("0"));
		  json_free(res);
		#endif
		  assertEquals_Primitive(json_as_int(test), 0);
		  assertEquals_Primitive(json_as_float(test), 0.0f);
		  #ifdef JSON_CASTABLE
			assertEquals(json_as_bool(test), false);
		  #endif
	
		  json_set_b(test, true);
		  assertEquals(json_type(test), JSON_BOOL);
		  #ifdef JSON_CASTABLE
			res = json_as_string(test);
			assertCStringSame(res, JSON_TEXT("true"));
			json_free(res);
			assertEquals_Primitive(json_as_int(test), 1);
			assertEquals_Primitive(json_as_float(test), 1.0f);
		  #endif
		  assertEquals(json_as_bool(test), true);

		  json_set_b(test, false);
		  assertEquals(json_type(test), JSON_BOOL);
		  #ifdef JSON_CASTABLE
			res = json_as_string(test);
			assertCStringSame(res, JSON_TEXT("false"));
			json_free(res);
			assertEquals_Primitive(json_as_int(test), 0);
			assertEquals_Primitive(json_as_float(test), 0.0f);
		  #endif
		  assertEquals(json_as_bool(test), false);
		  #ifdef JSON_CASTABLE
				  json_cast(test, JSON_NODE);
				  assertEquals(json_type(test), JSON_NODE);
				  assertEquals(json_size(test), 0);
				  json_push_back(test, json_new_a(JSON_TEXT("hi"), JSON_TEXT("world")));
				  json_push_back(test, json_new_a(JSON_TEXT("hello"), JSON_TEXT("mars")));
				  json_push_back(test, json_new_a(JSON_TEXT("salut"), JSON_TEXT("france")));
				  assertEquals(json_size(test), 3);
				  TestSuite::testParsingItself(test);

				  JSONNODE * casted = json_as_array(test);
				  #ifdef JSON_UNIT_TEST
					 assertNotEquals(((JSONNode*)casted) -> internal, ((JSONNode*)test) -> internal);
				  #endif
				  assertEquals(json_type(casted), JSON_ARRAY);
				  assertEquals(json_type(test), JSON_NODE);
				  assertEquals(json_size(test), 3);
				  assertEquals(json_size(casted), 3);
				  TestSuite::testParsingItself(casted);
		   #endif
				  UnitTest::SetPrefix("TestInspectors.cpp - Location");

		   #ifdef JSON_CASTABLE
				  #define CheckAt(parent, locale, text)\
					 if(JSONNODE * temp = json_at(parent, locale)){\
						json_char * _res = json_as_string(temp);\
						assertCStringSame(_res, text);\
						json_free(_res);\
					 } else {\
						FAIL(std::string("CheckAt: ") + #parent + "[" + #locale + "]");\
					 }

				  #define CheckNameAt(parent, locale, text)\
					 if(JSONNODE * temp = json_at(parent, locale)){\
						json_char * _res = json_name(temp);\
						assertCStringSame(_res, text);\
						json_free(_res);\
					 } else {\
						FAIL(std::string("CheckNameAt: ") + #parent + "[" + #locale + "]");\
					 }

		          CheckAt(casted, 0, JSON_TEXT("world"));
				  CheckAt(casted, 1, JSON_TEXT("mars"));
				  CheckAt(casted, 2, JSON_TEXT("france"));
				  CheckNameAt(casted, 0, JSON_TEXT(""));
				  CheckNameAt(casted, 1, JSON_TEXT(""));
				  CheckNameAt(casted, 2, JSON_TEXT(""));
	
				  CheckAt(test, 0, JSON_TEXT("world"));
				  CheckAt(test, 1, JSON_TEXT("mars"));
				  CheckAt(test, 2, JSON_TEXT("france"));
				  CheckNameAt(test, 0, JSON_TEXT("hi"));
				  CheckNameAt(test, 1, JSON_TEXT("hello"));
				  CheckNameAt(test, 2, JSON_TEXT("salut"));
		  

				  #define CheckGet(parent, locale, text)\
					 if(JSONNODE * temp = json_get(parent, locale)){\
						json_char * _res = json_as_string(temp);\
						assertCStringSame(_res, text);\
						json_free(_res);\
					 } else {\
						FAIL(std::string("CheckGet: ") + #parent + "[" + #locale + "]");\
					 }

				  #ifdef JSON_CASE_INSENSITIVE_FUNCTIONS
					 #define CheckGetNoCase(parent, locale, text)\
						if(JSONNODE * temp = json_get_nocase(parent, locale)){\
							json_char * _res = json_as_string(temp);\
							assertCStringSame(_res, text);\
							json_free(_res);\
						} else {\
							FAIL(std::string("CheckGetNoCase: ") + #parent + "[" + #locale + "]");\
						}
				  #else
					 #define CheckGetNoCase(parent, locale, text)
				  #endif

				  CheckGet(test, JSON_TEXT("hi"), JSON_TEXT("world"));
				  CheckGetNoCase(test, JSON_TEXT("HI"), JSON_TEXT("world"));
				  CheckGet(test, JSON_TEXT("hello"), JSON_TEXT("mars"));
				  CheckGetNoCase(test, JSON_TEXT("HELLO"), JSON_TEXT("mars"));
				  CheckGet(test, JSON_TEXT("salut"), JSON_TEXT("france"));
				  CheckGetNoCase(test, JSON_TEXT("SALUT"), JSON_TEXT("france"));
	
				assertNull(json_get(test, JSON_TEXT("meh")));
				#ifdef JSON_CASE_INSENSITIVE_FUNCTIONS
					assertNull(json_get_nocase(test, JSON_TEXT("meh")));
				#endif
			#endif


		  #ifdef JSON_ITERATORS
			#ifdef JSON_CASTABLE
			 UnitTest::SetPrefix("TestInspectors.cpp - Iterators");
			 for(JSONNODE_ITERATOR it = json_begin(casted), end = json_end(casted); it != end; ++it){
				json_char * _res = json_name(*it);
				assertCStringSame(_res, JSON_TEXT(""));
				json_free(_res);
			 }
			#endif
		  #endif

		  #ifdef JSON_BINARY
			 UnitTest::SetPrefix("TestInspectors.cpp - Binary");
			 json_set_binary(test, (const unsigned char *)"Hello World", 11);
			 assertEquals(json_type(test), JSON_STRING);
			 json_char * _res = json_as_string(test);
			 assertCStringSame(_res, JSON_TEXT("SGVsbG8gV29ybGQ="));
			 json_free(_res);

			 unsigned long i;
			 if(char * bin = (char*)json_as_binary(test, &i)){
				assertEquals(i, 11);
				char * terminated = (char*)std::memcpy(std::malloc(i + 1), bin, i);
				terminated[i] = '\0';
				assertCStringEquals(terminated, "Hello World");
				json_free(bin);
				std::free(terminated);
			 } else {
				FAIL("as_binary failed");
			 }

			 json_set_a(test, JSON_TEXT("Hello World"));
			 assertEquals(json_type(test), JSON_STRING);
			 _res = json_as_string(test);
			 assertCStringSame(_res, JSON_TEXT("Hello World"));
			 json_free(_res);

			 #ifdef JSON_SAFE
				assertEquals(json_as_binary(test, &i), 0);
				assertEquals(i, 0);
			 #endif
		  #endif


		  json_delete(test);
		  #ifdef JSON_CASTABLE
			json_delete(casted);
		  #endif
    #else
		  JSONNode test = JSONNode(JSON_NULL);
		  #ifdef JSON_CASTABLE
			 assertEquals(test.as_string(), JSON_TEXT(""));
			 assertEquals(test.as_int(), 0);
			 assertEquals(test.as_float(), 0.0f);
			 assertEquals(test.as_bool(), false);
		  #endif

		  test = 15.5f;
		  assertEquals(test.type(), JSON_NUMBER);
		#ifdef JSON_CASTABLE
		  assertEquals(test.as_string(), JSON_TEXT("15.5"));
		#endif
		  assertEquals(test.as_int(), 15);
		  assertEquals(test.as_float(), 15.5f);
		  #ifdef JSON_CASTABLE
			 assertEquals(test.as_bool(), true);
		  #endif

		  test = 0.0f;
		  assertEquals(test.type(), JSON_NUMBER);
		#ifdef JSON_CASTABLE
		  assertEquals(test.as_string(), JSON_TEXT("0"));
		#endif
		  assertEquals(test.as_int(), 0);
		  assertEquals(test.as_float(), 0.0f);
		  #ifdef JSON_CASTABLE
			 assertEquals(test.as_bool(), false);
		  #endif

		  test = true;
		  assertEquals(test.type(), JSON_BOOL);
		  #ifdef JSON_CASTABLE
			 assertEquals(test.as_string(), JSON_TEXT("true"));
			 assertEquals(test.as_int(), 1);
			 assertEquals(test.as_float(), 1.0f);
		  #endif
		  assertEquals(test.as_bool(), true);

		  test = false;
		  assertEquals(test.type(), JSON_BOOL);
		  #ifdef JSON_CASTABLE
			 assertEquals(test.as_string(), JSON_TEXT("false"));
			 assertEquals(test.as_int(), 0);
			 assertEquals(test.as_float(), 0.0f);
		  #endif
		  assertEquals(test.as_bool(), false);

		  #ifdef JSON_CASTABLE
			 test.cast(JSON_NODE);
		  #else
			 test = JSONNode(JSON_NODE);
		  #endif
		  assertEquals(test.type(), JSON_NODE);
		  assertEquals(test.size(), 0);
		  test.push_back(JSONNode(JSON_TEXT("hi"), JSON_TEXT("world")));
		  test.push_back(JSONNode(JSON_TEXT("hello"), JSON_TEXT("mars")));
		  test.push_back(JSONNode(JSON_TEXT("salut"), JSON_TEXT("france")));
		  assertEquals(test.size(), 3);
		  TestSuite::testParsingItself(test);

		  #ifdef JSON_CASTABLE
			 JSONNode casted = test.as_array();
			 #ifdef JSON_UNIT_TEST
				assertNotEquals(casted.internal, test.internal);
			 #endif
			 assertEquals(casted.type(), JSON_ARRAY);
			 assertEquals(test.type(), JSON_NODE);
			 assertEquals(test.size(), 3);
			 assertEquals(casted.size(), 3);
			 TestSuite::testParsingItself(casted);
		  #endif

		  UnitTest::SetPrefix("TestInspectors.cpp - Location");

		  try {
			 #ifdef JSON_CASTABLE
				assertEquals(casted.at(0), JSON_TEXT("world"));
				assertEquals(casted.at(1), JSON_TEXT("mars"));
				assertEquals(casted.at(2), JSON_TEXT("france"));
				assertEquals(casted.at(0).name(), JSON_TEXT(""));
				assertEquals(casted.at(1).name(), JSON_TEXT(""));
				assertEquals(casted.at(2).name(), JSON_TEXT(""));
			 #endif
			 assertEquals(test.at(0), JSON_TEXT("world"));
			 assertEquals(test.at(1), JSON_TEXT("mars"));
			 assertEquals(test.at(2), JSON_TEXT("france"));
			 assertEquals(test.at(0).name(), JSON_TEXT("hi"));
			 assertEquals(test.at(1).name(), JSON_TEXT("hello"));
			 assertEquals(test.at(2).name(), JSON_TEXT("salut"));
		  } catch (std::out_of_range){
			 FAIL("exception caught");
		  }

		  try {
			 assertEquals(test.at(JSON_TEXT("hi")), JSON_TEXT("world"));
			 assertEquals(test.at(JSON_TEXT("hello")), JSON_TEXT("mars"));
			 assertEquals(test.at(JSON_TEXT("salut")), JSON_TEXT("france"));
			 #ifdef JSON_CASE_INSENSITIVE_FUNCTIONS
				assertEquals(test.at_nocase(JSON_TEXT("SALUT")), JSON_TEXT("france"));
				assertEquals(test.at_nocase(JSON_TEXT("HELLO")), JSON_TEXT("mars"));
				assertEquals(test.at_nocase(JSON_TEXT("HI")), JSON_TEXT("world"));
			 #endif
		  } catch (std::out_of_range){
			 FAIL("exception caught");
		  }

		  assertException(test.at(JSON_TEXT("meh")), std::out_of_range);
		  #ifdef JSON_CASE_INSENSITIVE_FUNCTIONS
			 assertException(test.at_nocase(JSON_TEXT("meh")), std::out_of_range);
		  #endif

		  assertEquals(test[JSON_TEXT("hi")], json_string(JSON_TEXT("world")));
		  assertEquals(test[JSON_TEXT("hello")], json_string(JSON_TEXT("mars")));
		  assertEquals(test[JSON_TEXT("salut")], json_string(JSON_TEXT("france")));
		  assertEquals(test[0], JSON_TEXT("world"));
		  assertEquals(test[1], JSON_TEXT("mars"));
		  assertEquals(test[2], JSON_TEXT("france"));

		  #ifdef JSON_ITERATORS
			#ifdef JSON_CASTABLE
			 UnitTest::SetPrefix("TestInspectors.cpp - Iterators");
			 for(JSONNode::iterator it = casted.begin(), end = casted.end(); it != end; ++it){
				assertEquals((*it).name(), JSON_TEXT(""));
			 }
			#endif
		  #endif

		  #ifdef JSON_BINARY
			 UnitTest::SetPrefix("TestInspectors.cpp - Binary");
			 test.set_binary((const unsigned char *)"Hello World", 11);
			 assertEquals(test.type(), JSON_STRING);
			 assertEquals(test.as_string(), JSON_TEXT("SGVsbG8gV29ybGQ="));
			 assertEquals(test.as_binary(), "Hello World");
			 assertEquals(test.as_binary().size(), 11);

			 test = JSON_TEXT("Hello World");
			 assertEquals(test.type(), JSON_STRING);
			 assertEquals(test.as_string(), JSON_TEXT("Hello World"));
			 #ifdef JSON_SAFE
				assertEquals(test.as_binary(), "");
			 #endif
		  #endif
		  
         #ifdef JSON_READ_PRIORITY
			//This is a regression test for a bug in at()
			json_string buffer(JSON_TEXT("{ \"myValue1\" : \"foo\", \"myValue2\" : \"bar\"}"));
			JSONNode current = libjson::parse(buffer);
			try {
				JSONNode & value1 = current[JSON_TEXT("myValue1")];
				assertEquals(value1.as_string(), JSON_TEXT("foo"));
				JSONNode & value2 = current[JSON_TEXT("myValue2")];
				assertEquals(value2.as_string(), JSON_TEXT("bar"));
			} catch (...){
				assertTrue(false);
			}
        #endif
    #endif
}