//------------------------------------------------------------------------------------------------- Console::ModalResult Console::msgBox( std::ctstring_t &a_text, std::ctstring_t &a_title, cuint_t &a_type ) const { xUNUSED(a_type); ModalResult mrRv; std::csize_t width = 100; ctchar_t cmdAbort = xT('a'); ctchar_t cmdIgnore = xT('i'); ctchar_t cmdRetry = xT('r'); std::tstring_t title; { title = _msgBoxLine(a_title, width) + Const::nl(); } std::tstring_t multiText; { std::vec_tstring_t text; String::split(a_text, Const::nl(), &text); xFOR_EACH_CONST(std::vec_tstring_t, it, text) { multiText += _msgBoxLine(*it, width) + Const::nl(); } }
xNO_INLINE static void_t onInfo(int_t a_signal, siginfo_t *a_info, void_t *a_context) { xTEST_EQ(a_signal, a_info->si_signo); xUNUSED((ucontext_t *)a_context); xTRACE_FUNC; Trace() << Signal::infoDescription(*a_info) << "\n"; Trace() << Signal::decription(0) << "\n"; FileLog log(FileLog::lsDefaultMb); log.setFilePath(xT("crash.log")); std::ctstring_t msg = Format::str( xT("Crash info:\n\n") xT("Signal:\n{}\n\n") xT("StackTrace:\n{}"), Signal::infoDescription(*a_info), StackTrace().toString()); log.write(xT("%s\n"), msg.c_str()); std::tcout << StackTrace().toString() << std::endl; Application::exit(EXIT_FAILURE); }
static void_t * pvJob( void_t *a_pvParam ) { int_t iRv = - 1; long_t liId = *(static_cast<long *>( a_pvParam )); xUNUSED(liId); for (size_t i = 0; i < 10 /* g_cuiJobLoops */; ++ i) { iRv = ::pthread_mutex_lock(&g_mtMutex); xTEST_MSG_EQ(0, iRv, NativeError::format(iRv)); { ++ g_uiCounter; // Check the value of count and signal waiting thread when condition is reached if (g_uiCounter == g_cuiCounterMax) { iRv = ::pthread_cond_signal(&g_cndCondition); xTEST_MSG_EQ(0, iRv, NativeError::format(iRv)); #if 0 Tracer() << xT("pvJob(): thread: ") << liId << xT(" g_uiCounter: ") << g_uiCounter << xT(" threshold reached"); #endif } #if 0 Tracer() << xT("pvJob(): thread: ") << liId << xT(" g_uiCounter: ") << g_uiCounter << xT(" unlocking mutex"); #endif } iRv = ::pthread_mutex_unlock(&g_mtMutex); xTEST_MSG_EQ(0, iRv, NativeError::format(iRv)); // do some "work" so threads can alternate on mutex lock { uint_t uiRv = ::sleep(1); xUNUSED(uiRv); } } return xPTR_NULL; }
//------------------------------------------------------------------------------------------------- inline Console::ExModalResult Console::msgBox( std::ctstring_t &a_text, std::ctstring_t &a_title, cuint_t &a_type ) const { xUNUSED(a_type); #if xENV_WIN xTEST_DIFF(_wnd, xWND_NATIVE_HANDLE_NULL); xTEST_EQ(_stdIn.isValid(), true); xTEST_EQ(_stdOut.isValid(), true); #endif ExModalResult mrRv; enum EConsoleCmd { cmAbort = xT('a'), cmIgnore = xT('i'), cmRetry = xT('r') }; writeLine(); writeLine(xT("################################################################################")); writeLine(xT("# ") + a_title); writeLine(xT("#")); writeLine(xT("# ") + a_text); writeLine(xT("#")); writeLine(xT("################################################################################")); writeLine(); write(String::format(xT("\nAbort (%c), Ignore (%c), Retry (%c): "), cmAbort, cmIgnore, cmRetry)); EConsoleCmd cmRv = static_cast<EConsoleCmd>( std::tcin.get() ); std::tcin.ignore(); switch (cmRv) { case cmAbort: mrRv = mrAbort; writeLine(xT("Abort...")); break; case cmIgnore: mrRv = mrIgnore; writeLine(xT("Ignore...")); break; case cmRetry: mrRv = mrRetry; writeLine(xT("Retry...")); break; default: mrRv = mrRetry; writeLine(xT("Retry...")); break; } return mrRv; }
/* static */ inline std::tstring_t Uri::unescape( std::ctstring_t &a_uri ) { xUNUSED(a_uri); std::tstring_t sRv; // TODO: unescape return sRv; }
static void_t * pvWatch( void_t *a_pvParam ) { int_t iRv = - 1; long_t liId = *(static_cast<long *>( a_pvParam )); xUNUSED(liId); #if 0 Tracer() << "Starting pvWatch(): thread " << liId; #endif /* Lock mutex and wait for signal. Note that the pthread_cond_wait routine will automatically and atomically unlock mutex while it waits. Also, note that if COUNT_LIMIT is reached before this routine is run by the waiting thread, the loop will be skipped to prevent pthread_cond_wait from never returning. */ iRv = ::pthread_mutex_lock(&g_mtMutex); xTEST_MSG_EQ(0, iRv, NativeError::format(iRv)); { while (g_uiCounter < g_cuiCounterMax) { iRv = ::pthread_cond_wait(&g_cndCondition, &g_mtMutex); xTEST_MSG_EQ(0, iRv, NativeError::format(iRv)); #if 0 Tracer() << xT("pvCountWatch(): thread: ") << liId << xT(" Condition signal received"); #endif g_uiCounter += 125; #if 0 Tracer() << xT("pvCountWatch(): thread: ") << liId << xT(" g_uiCounter: ") << g_uiCounter; #endif } } iRv = ::pthread_mutex_unlock(&g_mtMutex); xTEST_MSG_EQ(0, iRv, NativeError::format(iRv)); return xPTR_NULL; }
/* virtual */ void_t Test_SmtpClient::unit( culonglong_t &a_caseLoops ) { xUNUSED(a_caseLoops); //------------------------------------- //IPNET //std::ctstring_t csUser = "******"; //std::ctstring_t csPass = "******"; //std::ctstring_t csServer = "mail.ipnet.kiev.ua"; //ushort_t usPort = 25; //std::ctstring_t csFrom = "*****@*****.**"; //std::ctstring_t csTo = "*****@*****.**"; //std::ctstring_t csFilePath = "C:/Temp/test.eml"; //std::ctstring_t csDirPath = "C:/Temp"; //------------------------------------- //CourierMS std::ctstring_t csUser = xT("test_1"); std::ctstring_t csPass = xT("test_1"); std::ctstring_t csServer = xT("127.0.0.1"); ushort_t usPort = 25; std::ctstring_t csFrom = xT("*****@*****.**"); std::ctstring_t csTo = xT("*****@*****.**"); std::ctstring_t csFilePath = xT("C:/Temp2/test.eml"); std::ctstring_t csDirPath = xT("C:/Temp"); //------------------------------------- //hMailServer //std::ctstring_t csUser = "******"; //std::ctstring_t csPass = "******"; //std::ctstring_t csServer = "127.0.0.1"; //ushort_t usPort = 25; //std::ctstring_t csFrom = "*****@*****.**"; //std::ctstring_t csTo = "*****@*****.**"; //std::ctstring_t csFilePath = "C:/Temp2/test.eml"; //std::ctstring_t csDirPath = "C:/Temp"; //------------------------------------- // ulong_t ulSum = 0; xUNUSED(ulSum); ulong_t ulSize = 0; xUNUSED(ulSize); ulong_t ulMsgID = 1; xUNUSED(ulMsgID); std::vector<ulong_t> veculList; ulong_t ulIndex = 1; xUNUSED(ulIndex); int_t iNum = 1; xUNUSED(iNum); std::ctstring_t csText = xT("HELO"); SmtpClient objSmtp; //------------------------------------- //bCreate objSmtp.create(csUser, csPass, csServer, usPort); //------------------------------------- //bConnect objSmtp.connect(); //------------------------------------- //bLogin ////objSmtp.vLogin(); //------------------------------------- //bSend objSmtp.send(csText, csFrom, csTo); //------------------------------------- // vSendRaw // TEST: SmtpClient::sendRaw() #if xTODO g_vsRes = Dir::vsListFiles(csDirPath, "*.eml"); for (size_t i = 0; i < g_vsRes.size(); i ++) { objSmtp.vSendRaw(csDirPath + "\\" + g_vsRes.at(i), csFrom, csTo); /*LOG*///printf("Send msg %s\n", g_vsRes.at(i).c_str()); } #endif //------------------------------------- //bNoop objSmtp.noop(); //------------------------------------- //bRset objSmtp.rset(); //------------------------------------- //bDisconnect objSmtp.disconnect(); }
/*virtual*/ void_t Test_Condition::unit( culonglong_t &a_caseLoops ) { xUNUSED(a_caseLoops); #if xENV_UNIX && xTODO int_t iRv = - 1; pthread_t thThreads[3] = {0}; clong_t liId1 = 1L; clong_t liId2 = 2L; clong_t liId3 = 3L; // initialize { iRv = ::pthread_mutex_init(&g_mtMutex, xPTR_NULL); // mutex not recursive xTEST_MSG_EQ(0, iRv, NativeError::format(iRv)); iRv = ::pthread_cond_init(&g_cndCondition, xPTR_NULL); xTEST_MSG_EQ(0, iRv, NativeError::format(iRv)); // for portability, explicitly create threads in a joinable state pthread_attr_t atAttr /* = {{0}} */; iRv = ::pthread_attr_init(&atAttr); xTEST_MSG_EQ(0, iRv, NativeError::format(iRv)); iRv = ::pthread_attr_setdetachstate(&atAttr, PTHREAD_CREATE_JOINABLE); xTEST_MSG_EQ(0, iRv, NativeError::format(iRv)); iRv = ::pthread_create(&thThreads[0], &atAttr, pvWatch, (void_t *)&liId1); xTEST_MSG_EQ(0, iRv, NativeError::format(iRv)); iRv = ::pthread_create(&thThreads[1], &atAttr, pvJob, (void_t *)&liId2); xTEST_MSG_EQ(0, iRv, NativeError::format(iRv)); iRv = ::pthread_create(&thThreads[2], &atAttr, pvJob, (void_t *)&liId3); xTEST_MSG_EQ(0, iRv, NativeError::format(iRv)); iRv = ::pthread_attr_destroy(&atAttr); xTEST_MSG_EQ(0, iRv, NativeError::format(iRv)); } // wait for all threads to complete for (size_t i = 0; i < g_cuiThreadsNum; ++ i) { iRv = ::pthread_join(thThreads[i], xPTR_NULL); xTEST_MSG_EQ(0, iRv, NativeError::format(iRv)); } #if 0 Tracer() << xT("Main(): waited on ") << g_cuiThreadsNum << xT(" threads. Done"); #endif // clean up { iRv = ::pthread_cond_destroy(&g_cndCondition); xTEST_MSG_EQ(0, iRv, NativeError::format(iRv)); iRv = ::pthread_mutex_destroy(&g_mtMutex); xTEST_MSG_EQ(0, iRv, NativeError::format(iRv)); } // ::exit(0); #if xTEMP_DISABLED Condition cond; cond.mutex(); cond.handle(); cond.create(); cond.wait(5000UL); cond.signal(); cond.broadcast(); #endif #endif // xENV_UNIX }
//------------------------------------------------------------------------------------------------- int_t xTMAIN(int_t a_argsNum, tchar_t *a_args[]) { xUNUSED(a_argsNum); xUNUSED(a_args); { #if 1 std::vector<int_t> signalNums; signalNums.push_back(SIGHUP); // Hangup (POSIX) signalNums.push_back(SIGINT); // Interrupt (ANSI) signalNums.push_back(SIGQUIT); // Quit (POSIX) signalNums.push_back(SIGILL); // Illegal instruction (ANSI) signalNums.push_back(SIGTRAP); // Trace trap (POSIX) signalNums.push_back(SIGABRT); // Abort (ANSI) signalNums.push_back(SIGIOT); // IOT trap (4.2 BSD) signalNums.push_back(SIGBUS); // BUS error (4.2 BSD) signalNums.push_back(SIGFPE); // Floating-point exception (ANSI) signalNums.push_back(SIGKILL); // Kill); unblockable (POSIX) signalNums.push_back(SIGUSR1); // User-defined signal 1 (POSIX) signalNums.push_back(SIGSEGV); // Segmentation violation (ANSI) signalNums.push_back(SIGUSR2); // User-defined signal 2 (POSIX) signalNums.push_back(SIGPIPE); // Broken pipe (POSIX) signalNums.push_back(SIGALRM); // Alarm clock (POSIX) signalNums.push_back(SIGTERM); // Termination (ANSI) signalNums.push_back(SIGSTKFLT); // Stack fault signalNums.push_back(SIGCLD); // Same as SIGCHLD (System V) signalNums.push_back(SIGCHLD); // Child status has changed (POSIX) signalNums.push_back(SIGCONT); // Continue (POSIX) signalNums.push_back(SIGSTOP); // Stop); unblockable (POSIX) signalNums.push_back(SIGTSTP); // Keyboard stop (POSIX) signalNums.push_back(SIGTTIN); // Background read from tty (POSIX) signalNums.push_back(SIGTTOU); // Background write to tty (POSIX) signalNums.push_back(SIGURG); // Urgent condition on socket (4.2 BSD) signalNums.push_back(SIGXCPU); // CPU limit exceeded (4.2 BSD) signalNums.push_back(SIGXFSZ); // File size limit exceeded (4.2 BSD) signalNums.push_back(SIGVTALRM); // Virtual alarm clock (4.2 BSD) signalNums.push_back(SIGPROF); // Profiling alarm clock (4.2 BSD) signalNums.push_back(SIGWINCH); // Window size change (4.3 BSD); Sun) signalNums.push_back(SIGPOLL); // Pollable event occurred (System V) signalNums.push_back(SIGIO); // I/O now possible (4.2 BSD) signalNums.push_back(SIGPWR); // Power failure restart (System V) signalNums.push_back(SIGSYS); // Bad system call Application application(xT("[app_name]_guid")); Application::setName(xT("[app_name]")); #if 0 application.setName(xT("[app_name]")); application.setDecription(xT("[decription]")); application.setUsage(xT("[usage]")); application.setHelp(xT("[help]")); application.setCopyrightYears(xT("[2008-2014]")); application.setVersionMajor(xT("[1]")); application.setVersionMinor(xT("[0]")); application.setVersionPatch(xT("[0]")); application.setVersionType(xT("[alpha]")); application.setVersionRevision(xT("[develop/970f53b]")); application.setVendorName(xT("[Skynowa Studio]")); application.setVendorDomain(xT("[com]")); application.setVendorAuthor(xT("[skynowa]")); application.setVendorUrl(xT("[http://bitbucket.org/skynowa/xlib]")); application.setVendorEmail(xT("[[email protected]]")); application.setVendorSkype(xT("[skynowa777]")); #endif #if 0 Trace() << xTRACE_VAR(application.name()) << xT("\n") << xTRACE_VAR(application.decription()) << xT("\n") << xTRACE_VAR(application.usage()) << xT("\n") << xTRACE_VAR(application.help()) << xT("\n") << xTRACE_VAR(application.copyrightYears()) << xT("\n") << xTRACE_VAR(application.versionMajor()) << xT("\n") << xTRACE_VAR(application.versionMinor()) << xT("\n") << xTRACE_VAR(application.versionPatch()) << xT("\n") << xTRACE_VAR(application.versionType()) << xT("\n") << xTRACE_VAR(application.versionRevision()) << xT("\n") << xTRACE_VAR(application.vendorName()) << xT("\n") << xTRACE_VAR(application.vendorDomain()) << xT("\n") << xTRACE_VAR(application.vendorAuthor()) << xT("\n") << xTRACE_VAR(application.vendorUrl()) << xT("\n") << xTRACE_VAR(application.vendorEmail()) << xT("\n") << xTRACE_VAR(application.vendorSkype()); #endif application.setOnSignals(signalNums, SignalFunctor::onSignals); application.setOnTerminate(SignalFunctor::onTerminate); application.setOnExit(SignalFunctor::onExit); // test error TestFail testFail; testFail.foo3(); #endif } #if xOPTION_TESTS // checks { #if xENV_UNIX SystemInfo info; xCHECK_MSG_RET(info.isUserAdmin(), xT("xLib_test: Can't run as root"), EXIT_FAILURE); #endif } // options (default) bool_t isUseTracing = true; ulonglong_t allLoops = 1ULL; ulonglong_t unitLoops = 1ULL; ulonglong_t caseLoops = 1ULL; { std::vec_tstring_t args; ProcessInfo info; info.setProcessId(Process::currentId()); info.commandLine(&args); if (a_argsNum == 1) { // OK, run tests with default params } else if (a_argsNum == 2) { // usage bool_t bRv = StringCI::compare(xT("-h"), args.at(1)) || StringCI::compare(xT("--help"), args.at(1)); if (!bRv) { std::tcout << xT("\nxLib_test: unknown switches\n") << std::endl; } else { std::tcout << xT("\nUsage: ./xLib_test [is_tracing] [all_loops] [unit_loops]\n") xT(" - xLib_test (binary file path)\n") xT(" - is_tracing (is tracing)\n") xT(" - all_loops (loops for all tests)\n") xT(" - unit_loops (loops for unit test)\n") xT(" - case_loops (loops for case test)\n") << std::endl; } return EXIT_SUCCESS; } else if (a_argsNum == 5) { // addition params isUseTracing = String::cast<bool_t> ( args.at(1) ); allLoops = String::cast<ulonglong_t>( args.at(2) ); unitLoops = String::cast<ulonglong_t>( args.at(3) ); caseLoops = String::cast<ulonglong_t>( args.at(4) ); } else { // fail std::tcout << xT("\nxLib_test: unknown switches\n") << std::endl; return EXIT_FAILURE; } } // add and run tests { TestManager manager(isUseTracing); // Test #if 1 manager.add(new Test_Test); #endif // Core #if 1 manager.add(new Test_Units); manager.add(new Test_Defines); manager.add(new Test_Limits); manager.add(new Test_Utils); manager.add(new Test_StdStream); manager.add(new Test_HandleT); manager.add(new Test_Type); manager.add(new Test_Flags); manager.add(new Test_Array); manager.add(new Test_AutoReset); manager.add(new Test_Char); manager.add(new Test_Locale); manager.add(new Test_String); manager.add(new Test_DateTime); manager.add(new Test_Com); manager.add(new Test_Application); #endif // Crypt #if 1 manager.add(new Test_Base64); #if xHAVE_OPENSSL_CRYPTO manager.add(new Test_Blowfish); #endif manager.add(new Test_Crc32); manager.add(new Test_Guid); manager.add(new Test_Random); // Db #if xHAVE_MYSQL manager.add(new Test_MySql); #endif #endif // Debug #if 1 manager.add(new Test_Debug); manager.add(new Test_BuildInfo); manager.add(new Test_StdError); manager.add(new Test_NativeError); manager.add(new Test_Exception); manager.add(new Test_StackTrace); manager.add(new Test_Debugger); manager.add(new Test_ErrorReport); manager.add(new Test_Profiler); manager.add(new Test_AutoProfiler); #endif // File system #if 1 manager.add(new Test_Path); manager.add(new Test_FileType); manager.add(new Test_File); manager.add(new Test_FileTemp); manager.add(new Test_Dll); manager.add(new Test_Finder); manager.add(new Test_Dir); manager.add(new Test_Volume); manager.add(new Test_Config); manager.add(new Test_Backup); #endif // Log #if 1 manager.add(new Test_Trace); manager.add(new Test_FileLog); manager.add(new Test_SystemLog); #endif // Net #if 1 manager.add(new Test_CookiePv0); manager.add(new Test_CookiePv1); manager.add(new Test_Cgi); manager.add(new Test_SocketInit); manager.add(new Test_DnsClient); // manager.add(new Test_TcpClient); // manager.add(new Test_TcpServer); manager.add(new Test_HttpClient); #endif // Patterns #if 1 manager.add(new Test_Observer); manager.add(new Test_Raii); manager.add(new Test_Singleton); #endif // Sync #if 1 manager.add(new Test_AtomicLongInt); manager.add(new Test_ThreadStorage); manager.add(new Test_Mutex); manager.add(new Test_AutoMutex); manager.add(new Test_IpcMutex); manager.add(new Test_AutoIpcMutex); // manager.add(new Test_Event); manager.add(new Test_Condition); manager.add(new Test_Semaphore); manager.add(new Test_IpcSemaphore); // manager.add(new Test_Sleeper); // manager.add(new Test_Thread); // manager.add(new Test_ThreadPool); manager.add(new Test_Process); #endif // Gui #if 1 manager.add(new Test_MsgBox); #endif // System #if 1 manager.add(new Test_Environment); manager.add(new Test_SystemInfo); manager.add(new Test_ProcessInfo); manager.add(new Test_Console); manager.add(new Test_Shell); #endif manager.run(allLoops, unitLoops, caseLoops); } #endif // xOPTION_TESTS return EXIT_SUCCESS; }