END_NCBI_SCOPE int main(int argc, const char* argv[]) { USING_NCBI_SCOPE; TFTP_Flags flag = 0; SConnNetInfo* net_info; auto_ptr<CNcbiRegistry> reg; size_t i, j, k, l, m, n, size; reg.reset(s_CreateRegistry()); CONNECT_Init(reg.get()); // Set error posting and tracing on maximum SetDiagTrace(eDT_Enable); SetDiagPostLevel(eDiag_Info); SetDiagPostAllFlags(SetDiagPostAllFlags(eDPF_Default) | eDPF_All | eDPF_OmitInfoSev); UnsetDiagPostFlag(eDPF_Line); UnsetDiagPostFlag(eDPF_File); UnsetDiagPostFlag(eDPF_Location); UnsetDiagPostFlag(eDPF_LongFilename); SetDiagTraceAllFlags(SetDiagPostAllFlags(eDPF_Default)); if (argc <= 1) g_NCBI_ConnectRandomSeed = (int) time(0) ^ NCBI_CONNECT_SRAND_ADDEND; else g_NCBI_ConnectRandomSeed = atoi(argv[1]); CORE_LOGF(eLOG_Note, ("Random SEED = %u", g_NCBI_ConnectRandomSeed)); srand(g_NCBI_ConnectRandomSeed); LOG_POST(Info << "Test 0 of 9: Checking error log setup"); ERR_POST(Info << "Test log message using C++ Toolkit posting"); CORE_LOG(eLOG_Note, "Another test message using C Toolkit posting"); LOG_POST(Info << "Test 0 passed\n"); LOG_POST(Info << "Test 1 of 9: Memory stream"); // Testing memory stream out-of-sequence interleaving operations m = (rand() & 0x00FF) + 1; size = 0; const IOS_BASE::iostate ex = IOS_BASE::badbit; for (n = 0; n < m; n++) { CConn_MemoryStream* ms = 0; string data, back; size_t sz = 0; #if 0 LOG_POST(Info << " Micro-test " << (int) n << " of " << (int) m << " start"); #endif k = (rand() & 0x00FF) + 1; for (i = 0; i < k; i++) { l = (rand() & 0x00FF) + 1; string bit; bit.resize(l); for (j = 0; j < l; j++) { bit[j] = "0123456789"[rand() % 10]; } #if 0 LOG_POST(Info << " Data bit at " << (unsigned long) sz << ", " << (unsigned long) l << " byte(s) long: " << bit); #endif sz += l; data += bit; if (ms) assert(*ms << bit); else if (i == 0) { switch (n % 4) { case 0: #if 0 LOG_POST(Info << " CConn_MemoryStream()"); #endif ms = new CConn_MemoryStream; ms->exceptions(ex); assert(*ms << bit); break; case 1: {{ BUF buf = 0; assert(BUF_Write(&buf, bit.data(), l)); #if 0 LOG_POST(Info << " CConn_MemoryStream(BUF)"); #endif ms = new CConn_MemoryStream(buf, eTakeOwnership); ms->exceptions(ex); break; }} default: break; } } } switch (n % 4) { case 2: #if 0 LOG_POST(Info << " CConn_MemoryStream(" << (unsigned long) data.size() << ')'); #endif ms = new CConn_MemoryStream(data.data(),data.size(), eNoOwnership); break; case 3: {{ BUF buf = 0; assert(BUF_Append(&buf, data.data(), data.size())); #if 0 LOG_POST(Info << " CConn_MemoryStream(BUF, " << (unsigned long) data.size() << ')'); #endif ms = new CConn_MemoryStream(buf, eTakeOwnership); break; }} default: break; } assert(ms); if (!(rand() & 1)) { assert(*ms << endl); *ms >> back; IOS_BASE::iostate state = ms->rdstate(); assert(state == IOS_BASE::goodbit); SetDiagTrace(eDT_Disable); ms->exceptions(ex | IOS_BASE::eofbit); try { *ms >> ws; } catch (IOS_BASE::failure& ) { state = ms->rdstate(); } #if defined(NCBI_COMPILER_GCC) # if NCBI_COMPILER_VERSION == 510 && (!defined(_GLIBCXX_USE_CXX11_ABI) || _GLIBCXX_USE_CXX11_ABI != 0) catch (...) { // WORKAROUND: // At least GCC 5.1.0 in optimized mode and using new ABI: // fails to catch "IOS_BASE::failure" above. state = ms->rdstate(); } # endif #endif _ASSERT(state & IOS_BASE::eofbit); SetDiagTrace(eDT_Enable); ms->clear(); } else
END_NCBI_SCOPE int main(int argc, const char* argv[]) { USING_NCBI_SCOPE; CNcbiRegistry* reg; TFTP_Flags flag = 0; SConnNetInfo* net_info; size_t i, j, k, l, m, n, size; reg = s_CreateRegistry(); CONNECT_Init(reg); // Set error posting and tracing on maximum SetDiagTrace(eDT_Enable); SetDiagPostLevel(eDiag_Info); SetDiagPostAllFlags(eDPF_All | eDPF_OmitInfoSev); UnsetDiagPostFlag(eDPF_Line); UnsetDiagPostFlag(eDPF_File); UnsetDiagPostFlag(eDPF_Location); UnsetDiagPostFlag(eDPF_LongFilename); SetDiagTraceAllFlags(SetDiagPostAllFlags(eDPF_Default)); if (argc <= 1) g_NCBI_ConnectRandomSeed = (int) time(0) ^ NCBI_CONNECT_SRAND_ADDEND; else g_NCBI_ConnectRandomSeed = atoi(argv[1]); CORE_LOGF(eLOG_Note, ("Random SEED = %u", g_NCBI_ConnectRandomSeed)); srand(g_NCBI_ConnectRandomSeed); LOG_POST(Info << "Test 0 of 9: Checking error log setup"); ERR_POST(Info << "Test log message using C++ Toolkit posting"); CORE_LOG(eLOG_Note, "Another test message using C Toolkit posting"); LOG_POST(Info << "Test 0 passed\n"); LOG_POST("Test 1 of 9: Memory stream"); // Testing memory stream out-of-sequence interleaving operations m = (rand() & 0x00FF) + 1; size = 0; for (n = 0; n < m; n++) { CConn_MemoryStream* ms = 0; string data, back; size_t sz = 0; #if 0 LOG_POST(" Micro-test " << (int) n << " of " << (int) m << " start"); #endif k = (rand() & 0x00FF) + 1; for (i = 0; i < k; i++) { l = (rand() & 0x00FF) + 1; string bit; bit.resize(l); for (j = 0; j < l; j++) { bit[j] = "0123456789"[rand() % 10]; } #if 0 LOG_POST(" Data bit at " << (unsigned long) sz << ", " << (unsigned long) l << " byte(s) long: " << bit); #endif sz += l; data += bit; if (ms) assert(*ms << bit); else if (i == 0) { switch (n % 4) { case 0: #if 0 LOG_POST(" CConn_MemoryStream()"); #endif ms = new CConn_MemoryStream; assert(*ms << bit); break; case 1: {{ BUF buf = 0; assert(BUF_Write(&buf, bit.data(), l)); #if 0 LOG_POST(" CConn_MemoryStream(BUF)"); #endif ms = new CConn_MemoryStream(buf, eTakeOwnership); break; }} default: break; } } } switch (n % 4) { case 2: #if 0 LOG_POST(" CConn_MemoryStream(" << (unsigned long) data.size() << ')'); #endif ms = new CConn_MemoryStream(data.data(),data.size(), eNoOwnership); break; case 3: {{ BUF buf = 0; assert(BUF_Append(&buf, data.data(), data.size())); #if 0 LOG_POST(" CConn_MemoryStream(BUF, " << (unsigned long) data.size() << ')'); #endif ms = new CConn_MemoryStream(buf, eTakeOwnership); break; }} default: break; } assert(ms); if (!(rand() & 1)) { assert(*ms << endl); *ms >> back; assert(ms->good()); SetDiagTrace(eDT_Disable); *ms >> ws; SetDiagTrace(eDT_Enable); ms->clear(); } else