void GBLStorageManagerStateTestBB::RetrieveStateTest( CKContext *ctx ) { XString outputStr; XString data; outputStr.Format( "Calling RetrieveState( %d, &<data>, %d, %d )", (int)testUserID, (int)testLAEID, componentID ); OutputTestText( ctx, outputStr ); StartTimeMeasure(); CGBLCOError res = pInterface->RetrieveState( testUserID, &data, testLAEID, componentID ); StopAndOutputTimeMeasure( ctx ); outputStr.Format( "RetrieveState result: %s", (const char*)res ); OutputTestText( ctx, outputStr ); if (res == CGBLCOError::EGBLCOErrorType::GBLCO_OK) { outputStr.Format( "State data retrieved: %s", data.Str() ); OutputTestText( ctx, outputStr ); if( testData == data ) OutputTestText( ctx, XString("TEST PASSED") ); else OutputTestText( ctx, XString("Retrieved data doesn't match saved data\r\nTEST FAILED") ); } else OutputTestText( ctx, XString("TEST FAILED") ); }
void CGBLStorageManagerTestBBBase::RunUnitTests( CKContext *ctx, TestCase *testCases, int numTests, XString &testRunTitle ) { XString outputString; // Initialise the test run timer totalExecutionTime = 0; // Generate the current time time_t seconds; seconds = time (NULL); struct tm * timeinfo; timeinfo = localtime ( &seconds ); // Output a formatted intro to the test run outputString = "############################################################################\r\n"; outputString << testRunTitle << "\r\n"; outputString << asctime (timeinfo) << "\r\n"; outputString << "############################################################################\r\n"; OutputTestText( ctx, outputString ); // Iterate over each test and execute it... for( int i = 0; i < numTests; i++ ) { XString testIntroText; // First, write some intro text to the output OutputTestText( ctx, XString("----------------------------------------------------------------------------") ); testIntroText.Format( "Test number %d\r\nExecuting unit test '%s'...", i+1, testCases[i].testName ); OutputTestText( ctx, testIntroText ); OutputTestText( ctx, XString("----------------------------------------------------------------------------\r\n") ); // Now execute the actual test case testCases[i].testFunction( ctx ); // Now append some end of test text testIntroText.Format( "End of test number %d", i+1 ); OutputTestText( ctx, testIntroText ); OutputTestText( ctx, XString("----------------------------------------------------------------------------\r\n") ); } outputString = ""; outputString << "############################################################################\r\n"; outputString << "Total execution time = " << totalExecutionTime << " seconds\r\n"; outputString << "############################################################################\r\n"; outputString << "######################## END OF TEST ###########################"; OutputTestText( ctx, outputString ); }
/* ******************************************************************* * Function: int BehaviourFunction( const CKBehaviorContext& behaviorContext ) * * Description : The execution function is the function that will be called * during the process loop of the behavior engine, if the behavior * is defined as using an execution function. This function is not * called if the behavior is defined as a graph. This function is the * heart of the behavior: it should compute the essence of the behavior, * in an incremental way. The minimum amount of computing should be * done at each call, to leave time for the other behaviors to run. * The function receives the delay in milliseconds that has elapsed * since the last behavioral process, and should rely on this value to * manage the amount of effect it has on its computation, if the effect * of this computation relies on time. * * Parameters : * behaviourContext r Behavior context reference, which gives access to * frequently used global objects ( context, level, manager, etc... ) * * Returns : int, If it is done, it should return CKBR_OK. If it returns * CKBR_ACTIVATENEXTFRAME, the behavior will again be called * during the next process loop. * ******************************************************************* */ int GBLStorageManagerStateTestBB::BehaviourFunction( const CKBehaviorContext& behaviorContext ) { beh = behaviorContext.Behavior; CKContext *ctx = behaviorContext.Context; // Randomise srand( (unsigned)time( NULL ) ); // Get a pointer to the required interface now pInterface = GetStateInterfacePointer( ctx ); // Generate some values that can be used throughout the tests testUserID = (rand() % 999) + 1; testLAEID = (rand() % 999) + 1; if( pInterface ) { // Simply execute the unit tests... RunUnitTests( ctx, testCases, sizeof(testCases)/sizeof(TestCase), testRunName ); } else OutputTestText( ctx, XString("Cannot acquire state interface. Unable to execute tests.") ); beh->ActivateInput(0, 0); beh->ActivateOutput(0); return CKBR_OK; }
inline FString RBUF_STRING(const uint8_t *p, size_t pos, size_t len) { const char *const begin = static_cast<const char *>(RBUFP(p, pos)); const char *const end = begin + len; const char *const mid = std::find(begin, end, '\0'); return XString(begin, mid, nullptr); }
inline FString RFIFO_STRING(int fd, size_t pos, size_t len) { const char *const begin = static_cast<const char *>(RFIFOP(fd, pos)); const char *const end = begin + len; const char *const mid = std::find(begin, end, '\0'); return XString(begin, mid, nullptr); }
void MD5_to_str(MD5_state state, md5_string& out_) { md5_binary bin; MD5_to_bin(state, bin); char out[0x20]; for (int i = 0; i < 0x10; i++) out[2 * i] = hex[bin[i] >> 4], out[2 * i + 1] = hex[bin[i] & 0xf]; out_ = stringish<md5_string>(XString(out, out + 0x20, nullptr)); }
int DirToArray(const CKBehaviorContext& behcontext) { CKBehavior* beh = behcontext.Behavior; CKContext* ctx = behcontext.Context; XString filename((CKSTRING) beh->GetInputParameterReadDataPtr(0)); XString Mask((CKSTRING) beh->GetInputParameterReadDataPtr(1)); int rec; beh->GetInputParameterValue(2,&rec); if( beh->IsInputActive(0) ){ beh->ActivateInput(0,FALSE); flist.erase(flist.begin(),flist.end()); CKDirectoryParser MyParser(filename.Str(),Mask.Str(),rec); char* str = NULL; while(str = MyParser.GetNextFile()) flist.push_back(XString(str)); counter = 0; beh->ActivateInput(1,TRUE); } if( beh->IsInputActive(1) ){ beh->ActivateInput(1,FALSE); if ( counter < flist.size() ){ XString entry = flist.at(counter); CKParameterOut * pout = beh->GetOutputParameter(0); pout->SetStringValue(entry.Str() ); counter++; beh->SetOutputParameterValue(1,&counter); beh->ActivateOutput(1); }else{ beh->SetOutputParameterValue(1,&counter); counter = 0 ; beh->ActivateOutput(0); } } return 0; }
void CPWad::AddEntry (DIR_ENTRY &entry) { char namebuf[9]; namebuf[8] = 0; memcpy (namebuf, entry.resource_name, 8); XString name (namebuf); // -=- test for map level marker -=- if ((((name[0] == 'E') && (name[2] == 'M')) || ((name[0] == 'M') && (name[1] == 'A') && (name[2] == 'P'))) && (entry.resource_size == 0)) { // -=- add map header entry to dir and set up current map -=- directory.AddItem (currentmap = new CDirEntry (name, 0, 0)); } else { // -=- put all map related records in the list in the sub dir of the map -=- // -=- all other items go in the main dir -=- if ((name == XString("THINGS")) || (name == XString("LINEDEFS")) || (name == XString("SIDEDEFS")) || (name == XString("VERTEXES")) || (name == XString("SEGS")) || (name == XString("SSECTORS")) || (name == XString("NODES")) || (name == XString("SECTORS")) || (name == XString("REJECT")) || (name == XString("BLOCKMAP"))) { currentmap->subdir.AddItem (new CDirEntry (name, entry.resource_offset, entry.resource_size)); } else { directory.AddItem (new CDirEntry (name, entry.resource_offset, entry.resource_size)); currentmap = 0; } } }
void GBLStorageManagerStateTestBB::StoreExistingStateTest( CKContext *ctx ) { XString outputStr; testData = "StoreExistingStateTest test state data - updated after initial storage"; outputStr.Format( "Calling StoreState( %d, %s, %d, %d )", (int)testUserID, testData.Str(), (int)testLAEID, componentID ); OutputTestText( ctx, outputStr ); StartTimeMeasure(); CGBLCOError res = pInterface->StoreState( testUserID, testData, testLAEID, componentID ); StopAndOutputTimeMeasure( ctx ); outputStr.Format( "StoreState result: %s", (const char*)res ); OutputTestText( ctx, outputStr ); if (res == CGBLCOError::EGBLCOErrorType::GBLCO_OK) { OutputTestText( ctx, XString("TEST PASSED") ); } else OutputTestText( ctx, XString("TEST FAILED") ); }
XString pFactory::_getMaterialsAsEnumeration(const TiXmlDocument * doc) { if (!doc) { return XString(""); } XString result("None=0"); int counter = 1; /************************************************************************/ /* try to load settings from xml : */ /************************************************************************/ if ( doc) { const TiXmlElement *root = getFirstDocElement(doc->RootElement()); for (const TiXmlNode *child = root->FirstChild(); child; child = child->NextSibling() ) { if ( (child->Type() == TiXmlNode::ELEMENT)) { XString name = child->Value(); if (!strcmp(child->Value(), "material" ) ) { const TiXmlElement *sube = (const TiXmlElement*)child; const char* matName = NULL; matName = sube->Attribute("name"); if (matName && strlen(matName)) { if (result.Length()) { result << ","; } result << matName; result << "=" << counter; counter ++; } } } } } return result; }
void GBLStorageManagerStateTestBB::RetrieveStateTestInvalidParameters( CKContext *ctx ) { XString outputStr; XString data; CGBLUserID invalidUser; outputStr.Format( "Calling RetrieveState( %d, &<data>, %d, %d )", (int)invalidUser, (int)testLAEID, componentID ); OutputTestText( ctx, outputStr ); StartTimeMeasure(); CGBLCOError res = pInterface->RetrieveState( invalidUser, &data, testLAEID, componentID ); StopAndOutputTimeMeasure( ctx ); outputStr.Format( "RetrieveState result: %s", (const char*)res ); OutputTestText( ctx, outputStr ); if( res == CGBLCOError::EGBLCOErrorType::GBLCO_LOCAL && (int)res == GBLSM_ERROR_GENERAL_INCORRECT_PARAM ) { OutputTestText( ctx, XString("TEST PASSED") ); } else OutputTestText( ctx, XString("TEST FAILED") ); }
int main (int argc, char** argv) { set_new_handler (NoMemory); cerr << version_info << endl; if (argc > 3) { // -=- Read in PWAD directory -=- //CPWad wad (XString(argv[1]) + XString(".WAD")); CPWad wad = XString(argv[1]); // -=- All OK ? -=- if (!wad.Valid ()) { cerr << "Failed Reading PWAD " << argv[1] << endl; exit (0); } XString map (argv[2]); int threshold = atoi (argv[3]); if ((threshold >= 32) && (threshold <= 4096)) { CReject rej (wad, map); if (rej.Valid ()) { rej.RejectAll (); cout << "Calculating Reject table...." << flush; rej.RejectDefault (threshold); cout << "Done." << endl; cout << "Writing Reject table...." << flush; wad.Write (rej.GetRejectData(), map, "REJECT"); cout << "Done." << endl; } } else { cerr << "Treshold must be between 32 and 4096" << endl; } } else { cerr << "USAGE: REJECT <WADNAME> <MAPNAME> <THRESHOLD>" << endl; cerr << " eg: reject mywad e1m1 600" << endl; } return 0; }
AString slurp() { MString tmp; char buf[4096]; while (true) { ssize_t rv = rfd.read(buf, sizeof(buf)); if (rv == -1) { if (errno != EAGAIN) return "Error, read failed :("_s; rv = 0; } if (rv == 0) break; tmp += XString(buf + 0, buf + rv, nullptr); } return AString(tmp); }
/// Return a pair of strings, {spellname, parameter} /// Parameter may be empty. static std::pair<XString, XString> magic_tokenise(XString src) { auto seeker = std::find(src.begin(), src.end(), ' '); if (seeker == src.end()) { return {src, XString()}; } else { XString rv1 = src.xislice_h(seeker); ++seeker; while (seeker != src.end() && *seeker == ' ') ++seeker; // Note: this very well could be empty XString rv2 = src.xislice_t(seeker); return {rv1, rv2}; } }
RecvResult recv_vpacket(Session *s, Packet_Head<id>& head, AString& repeat) { static_assert(id == Packet_Head<id>::PACKET_ID, "Packet_Head<id>::PACKET_ID"); static_assert(headsize == sizeof(NetPacket_Head<id>), "NetPacket_Head<id>"); static_assert(id == Packet_Repeat<id>::PACKET_ID, "Packet_Repeat<id>::PACKET_ID"); static_assert(repeatsize == sizeof(NetPacket_Repeat<id>), "NetPacket_Repeat<id>"); static_assert(repeatsize == 1, "repeatsize"); NetPacket_Head<id> net_head; std::vector<NetPacket_Repeat<id>> net_repeat; RecvResult rv = net_recv_vpacket(s, net_head, net_repeat); assert (head.magic_packet_id == Packet_Head<id>::PACKET_ID); if (rv == RecvResult::Complete) { if (!network_to_native(&head, net_head)) return RecvResult::Error; // reinterpret_cast is needed to correctly handle an empty vector const char *begin = sign_cast<const char *>(net_repeat.data()); const char *end = begin + net_repeat.size(); end = std::find(begin, end, '\0'); repeat = XString(begin, end, nullptr); } return rv; }
RString::RString(LString l) : owned(nullptr) { *this = XString(l); }
RString::RString(ZString z) : owned(nullptr) { *this = XString(z); }
RString::RString(const SString& s) : owned(nullptr) { *this = XString(s); }
::rux::String& Double::ToString( void ) { declare_stack_variable( char , text , 64 ); ::rux::safe_sprintf( text , 64 , "%.2f" , _value ); return XString( text , XEnumCodePage_UTF8 , 1 , NULL , __FILE__ , __LINE__ )++; };
void CGBLStorageManagerTestBBBase::DescribeArray( CKDataArray *fieldValues, CKContext *ctx ) { int cols = fieldValues->GetColumnCount(); int rows = fieldValues->GetRowCount(); if (cols == 0) { OutputTestText( ctx, XString("Array contains no columns") ); return; } if (rows == 0) { OutputTestText( ctx, XString("Array contains no rows (no results were returned)") ); return; } XString opStr; opStr.Format( "Results (%d columns, %d rows):", cols, rows ); OutputTestText( ctx, opStr ); for (int row = 0; row < rows; row++) { for (int i=0; i<cols; i++) { XString str; str.Format( "%s (", fieldValues->GetColumnName(i) ); int type = fieldValues->GetColumnType(i); if (type == CKARRAYTYPE_PARAMETER) { str << ctx->GetParameterManager()->ParameterGuidToName(fieldValues->GetColumnParameterGuid(i)); } else { switch (fieldValues->GetColumnType(i)) { case CKARRAYTYPE_INT: str << "int"; break; case CKARRAYTYPE_FLOAT: str << "float"; break; case CKARRAYTYPE_STRING: str << "string"; break; case CKARRAYTYPE_OBJECT: str << "object"; break; default: str << "UNKNOWN TYPE"; break; } } str << ") : "; CKSTRING valueField = NULL; int labelLength = fieldValues->GetElementStringValue(row, i, NULL); valueField = new CKCHAR[labelLength]; fieldValues->GetElementStringValue(row, i, valueField); str << valueField; OutputTestText( ctx, str ); delete [] valueField; } //trace << endl; } }
void PaintMe(HWND hwnd) { HDC hDC; PAINTSTRUCT ps; RECT rcWindow; HFONT hSysFont, hFont, hFontOld; LOGFONT lfFont; COLORREF crText; TCHAR szTextBuffer[50], szTextBuffer2[50], szInternetTime[5]; XString xsTextBuffer; int iFontSizePixel; GetWindowRect(hwnd, &rcWindow); OffsetRect(&rcWindow, -rcWindow.left, -rcWindow.top); hDC = BeginPaint(hwnd, &ps); SetBkMode(hDC, TRANSPARENT); if (bSelected == TRUE) { HBRUSH hBrush = GetSysColorBrush(COLOR_HIGHLIGHT); FillRect(hDC, &rcWindow, hBrush); DeleteObject(hBrush); } if (g_iTextSize == 0) { SHGetUIMetrics(SHUIM_FONTSIZE_PIXEL, &iFontSizePixel, sizeof(iFontSizePixel), NULL); } else { iFontSizePixel = MulDiv(g_iTextSize + MIN_FONT_SIZE - 1, DRA::LogPixelsY(), 72); } hSysFont = (HFONT) GetStockObject(SYSTEM_FONT); GetObject(hSysFont, sizeof(LOGFONT), &lfFont); //memset(&lfFont, 0, sizeof(LOGFONT)); lfFont.lfWeight = FW_SEMIBOLD; lfFont.lfHeight = -iFontSizePixel; hFont = CreateFontIndirect(&lfFont); hFontOld = (HFONT) SelectObject(hDC, hFont); crText = SendMessage(GetParent(hwnd), TODAYM_GETCOLOR, (WPARAM) TODAYCOLOR_TEXT, NULL); SetTextColor(hDC, crText); InflateRect(&rcWindow, -2, 0); _itot(g_iInternetTime, szInternetTime, 10); //_ttoi _tcscpy(szTextBuffer, _T("a\0")); GetTimeFormat(LOCALE_SYSTEM_DEFAULT, 0, &g_stLocalTime, g_xsLeftFormat.Replace(_T("'"), _T("'''")).GetBuffer(), szTextBuffer, sizeof szTextBuffer); GetDateFormat(LOCALE_SYSTEM_DEFAULT, 0, &g_stLocalTime, szTextBuffer, szTextBuffer2, sizeof szTextBuffer2); xsTextBuffer = XString(szTextBuffer2).Replace(_T("@"), XString(_T("@"), szInternetTime)); DrawText(hDC, xsTextBuffer.GetBuffer(), -1, &rcWindow, DT_VCENTER | DT_LEFT); _tcscpy(szTextBuffer, _T("a\0")); GetTimeFormat(LOCALE_SYSTEM_DEFAULT, 0, &g_stLocalTime, g_xsRightFormat.Replace(_T("'"), _T("'''")).GetBuffer(), szTextBuffer, sizeof szTextBuffer); GetDateFormat(LOCALE_SYSTEM_DEFAULT, 0, &g_stLocalTime, szTextBuffer, szTextBuffer2, sizeof szTextBuffer2); xsTextBuffer = XString(szTextBuffer2).Replace(_T("@"), XString(_T("@"), szInternetTime)); DrawText(hDC, xsTextBuffer.GetBuffer(), -1, &rcWindow, DT_VCENTER | DT_RIGHT); SelectObject(hDC, hFontOld); DeleteObject(hFont); EndPaint(hwnd, &ps); }
RString::RString(const TString& t) : owned(nullptr) { *this = XString(t); }
XString& XString::operator=(const char* cstr) { return (*this = XString(cstr)); }
XString Root(const XString& path) { size_t index = path.find_last_of("/\\"); return (XString::npos == index) ? XString() : path.substr(0,index+1); }
void createSQLControl(XString ss, int nWidth, XString *sDefinition, XString *s, XString *sAdditional, int *X, int nBorderLeft, int nBorderBottom, int nHeight, int nFocusOrder, XString *sSQLControls) { static char ac[1000]; *sDefinition += "Private SQL"; *sDefinition += ss; *sDefinition += " As "; bool bLabel = (ss == "Recordset" || ss == "Info"); bool bTextBox = ss == "GoTo"; bool bCommandButton = !bLabel && !bTextBox; if (bCommandButton) *sDefinition += "CommandButton\n"; else if (bLabel) *sDefinition += "Label\n"; else if (bTextBox) *sDefinition += "TextBox\n"; *s += "SQL"; *s += ss; *s += " = New "; if (bCommandButton) *s += "CommandButton"; else if (bLabel) *s += "Label"; else if (bTextBox) *s += "TextBox"; *s += "(Me)\n"; /* *s += "(Me, \"SQL"; *s += ss; *s += "\")\n"; */ if (bLabel){ if (ss == "Recordset"){ *s += "SQL"; *s += ss; *s += ".Caption = \" Recordset: \"\n"; } else { *s += "SQL"; *s += ss; *s += ".Caption = \"\"\n"; } } else if (bTextBox){ *s += "SQL"; *s += ss; *s += ".Value = \"\"\n"; } else if (bCommandButton){ *s += "SQL"; *s += ss; *s += ".Caption = \"\"\n"; } *s += "SQL"; *s += ss; *s += ".Name = \""; *s += "SQL"; *s += ss; *s += "\"\n"; if (bCommandButton){ *s += "SQL"; *s += ss; *s += ".Icon = \"SQL"; *s += ss; *s += ".png\"\n"; } *s += "SQL"; *s += ss; *s += ".X = "; sprintf(ac, "%d\n", nBorderLeft + *X); *s += XString(ac); *s += "SQL"; *s += ss; *s += ".Y = "; sprintf(ac, "%d\n", nHeight - nBorderBottom - 20); *s += XString(ac); *s += "SQL"; *s += ss; *s += ".Width = "; sprintf(ac, "%d\n", nWidth); *s += XString(ac); *s += "SQL"; *s += ss; *s += ".Height = 20\n"; if (bCommandButton || bTextBox){ *s += "SQL"; *s += ss; *s += ".FocusOrder = "; sprintf(ac, "%d\n", nFocusOrder); *s += XString(ac); } *s += "SQL"; *s += ss; *s += ".Layout = \"RelativeY\"\n\n"; if (!bLabel){ *sAdditional += "\nSub SQL"; *sAdditional += ss; *sAdditional += "_OnEvent()\n"; if (ss == "GoTo"){ *sAdditional += "Dim n As Integer\n"; *sAdditional += "n = Val( SQLGoTo.Value)\n"; *sAdditional += "If n < 1 Or n > Me.Length() Then\n"; *sAdditional += " SQLGoTo.SelectAll()\n"; *sAdditional += " Return\n"; *sAdditional += "End If\n"; *sAdditional += "If Not Me.GoTo(n) Then\n"; *sAdditional += " SQLGoTo.Value = \"\" & Me.Position()\n"; *sAdditional += "End If\n"; *sAdditional += "\nEnd Sub\n"; } else { *sAdditional += " Me."; if (ss == "AddNotFilter"){ *sAdditional += "AddFilter(\"<>\")\nEnd Sub\n"; } else if (ss == "SetNotFilter"){ *sAdditional += "SetFilter(\"<>\")\nEnd Sub\n"; } else if (ss == "AddNew"){ *sAdditional += "AddNew()\n"; if (sSQLControls->isEmpty() || sSQLControls->contains("GoTo")) *sAdditional += "SQLGoTo.Value = \"*\"\n"; *sAdditional += "\nEnd Sub\n"; } else { *sAdditional += ss; *sAdditional += "()\nEnd Sub\n"; } } } *X += nWidth; }