int test_main(int argc, char *argv[]) { if (argc == 1) { // no argument, lets run like we are in "check" const char * srcdir = getenv("srcdir"); BOOST_ASSERT(srcdir != NULL); g_testfile = std::string(srcdir); g_testfile += "/ljpegtest1.jpg"; } else { g_testfile = argv[1]; } RawData *decompData; File::Ptr s(new File(g_testfile.c_str())); RawContainer *container = new JfifContainer(s, 0); LJpegDecompressor decompressor(s.get(), container); decompData = decompressor.decompress(); boost::crc_optimal<16, 0x1021, 0xFFFF, 0, false, false> crc_ccitt2; const uint8_t * data = static_cast<uint8_t *>(decompData->data()); size_t data_len = decompData->size(); crc_ccitt2 = std::for_each( data, data + data_len, crc_ccitt2 ); BOOST_CHECK(crc_ccitt2() == 0x20cc); delete decompData; delete container; return 0; }
TEST(CryptingTest, EncryptStream) { std::stringstream strmIn; RawData expression; FillStream(strmIn, expression); std::stringstream strmOut; AesEncryptor encryptor(keyNormal, ivNormal); uint64_t encryptedSize = 0; ASSERT_NO_THROW(encryptedSize = encryptor.Encrypt(strmIn, strmOut, expression.size())); ASSERT_EQ(encryptedSize, expression.size()); EXPECT_EQ(encryptedSize, expression.size()); RawData encrypted(static_cast<unsigned int>(encryptedSize)); strmOut.read(reinterpret_cast<char*>(&encrypted[0]), encryptedSize); EXPECT_NE(encrypted, expression); }
TEST(CryptingTest, EncryptString) { RawData expression(StringToRawData("1234567890")); AesEncryptor encryptor(keyNormal, ivNormal); RawData encrypted; ASSERT_NO_THROW(encryptor.Encrypt(expression, encrypted)); EXPECT_EQ(encrypted.size(), expression.size()); EXPECT_NE(encrypted, expression); }
TEST(CryptingTest, DecryptStream) { std::stringstream strmIn; RawData expression; FillStream(strmIn, expression); std::stringstream strmEncrypted; AesEncryptor encryptor(keyNormal, ivNormal); encryptor.Encrypt(strmIn, strmEncrypted, expression.size()); // This test case must be passed above std::stringstream strmDecrypted; AesDecryptor decryptor(keyNormal, ivNormal); uint64_t decryptedSize = 0; ASSERT_NO_THROW(decryptedSize = decryptor.Decrypt(strmEncrypted, strmDecrypted, expression.size())); ASSERT_EQ(decryptedSize, expression.size()); RawData decrypted(static_cast<unsigned int>(decryptedSize)); strmDecrypted.read(reinterpret_cast<char*>(&decrypted[0]), decryptedSize); EXPECT_EQ(decrypted, expression); }
void CommandManager::onResponse(CCHttpClient* client, CCHttpResponse* response) { const string commandName = m_currentCommand->getName(); if (response->isSucceed()) { m_currentCommand->setCommandState(CommandStateResonsedProcessed); if (m_currentCommand->getMessageHandler()) { int responseCode = response->getResponseCode(); RawData* responseData = response->getResponseData(); int responseDataSize = responseData->size(); const char* data = &((*responseData)[0]); CCLOG("command %s response code %d length %d", commandName.c_str(), responseCode, responseDataSize); ResponseMessage message; bool decoded = message.ParseFromArray(data, responseDataSize); CCAssert(decoded, FORMAT("command %s decode fail data length=%d", commandName.c_str(), responseDataSize)); m_currentCommand->getMessageHandler()->setMessage(&message); m_currentCommand->getMessageHandler()->execute(); } } else { CCLOG("command %s fail errorcode=%d error message=%s", commandName.c_str(), response->getResponseCode(), response->getErrorBuffer()); int resendCount = m_currentCommand->getResendCount(); if (resendCount < MAX_RESEND_COUNT) { client->send(response->getHttpRequest()); m_currentCommand->setResendCount(resendCount + 1); CCLOG("resend command %s for the %d time(s)", commandName.c_str(), resendCount); } else { CCMessageBox(FORMAT("Command fail %s", commandName.c_str()), "Error"); } } }