nsresult TextEditorTest::TestInsertBreak() { nsCOMPtr<nsISelection>selection; nsresult result = mEditor->GetSelection(getter_AddRefs(selection)); TEST_RESULT(result); TEST_POINTER(selection.get()); nsCOMPtr<nsIDOMNode>anchor; result = selection->GetAnchorNode(getter_AddRefs(anchor)); TEST_RESULT(result); TEST_POINTER(anchor.get()); selection->Collapse(anchor, 0); // insert one break printf("inserting a break\n"); result = mTextEditor->InsertLineBreak(); TEST_RESULT(result); mEditor->DebugDumpContent(); // insert a second break adjacent to the first printf("inserting a second break\n"); result = mTextEditor->InsertLineBreak(); TEST_RESULT(result); mEditor->DebugDumpContent(); return result; }
nsresult TextEditorTest::InitDoc() { nsresult result = mEditor->SelectAll(); TEST_RESULT(result); result = mEditor->DeleteSelection(nsIEditor::eNext, nsIEditor::eStrip); TEST_RESULT(result); return result; }
/* else if (*pitch <= -PI/2)// limit to 90 deg { *pitch = -PI/2; } */ else if (*pitch <= - 0.75f*PI) // limit to 135deg { *pitch = - 0.75f*PI; } missedFrameCount = 0; if ((isActive == false) && (g_bTrackIRon)) { OTWDriver.SetHeadTracking(TRUE); // Retro 26/09/03 isActive = true; } FrameSignature = tid.wPFrameSignature; #ifdef DEBUG_TRACKIR_STUFF FILE* fp = fopen("TIR_Debug.txt","at"); fprintf(fp,"Yaw %f\t Pitch %f\n",tid.fNPYaw,tid.fNPPitch); fprintf(fp,"Yaw %f\t Pitch %f\n",*yaw,*pitch); fclose(fp); #endif } else { missedFrameCount++; if (missedFrameCount > 100) { isActive = false; OTWDriver.SetHeadTracking(FALSE); // Retro 26/09/03 } #ifdef DEBUG_TRACKIR_STUFF FILE* fp = fopen("TIR_Debug.txt","at"); fprintf(fp,"Missed frame # %i, FrameSig %i, NPFrameSig %i\n",missedFrameCount,FrameSignature,tid.wPFrameSignature); fclose(fp); #endif // yaw and pitch values stay unchanged so that looking via POV hat works } } } //********************************************************************** // Name: GetDllLocation // Authors: wk, Retro // Date: 26. Feb 2003 // Update: // // Description:Look in the registry for the path to the NPClient.dll.. // Taken form the NaturalPoint sample code //*********************************************************************/ char* GetDllLocation(char* loc) { unsigned char *szValue; char* retval = NULL; DWORD dwSize; HKEY pKey = NULL; //********************************************************************** //open the registry key //*********************************************************************/ if (RegOpenKeyEx( HKEY_CURRENT_USER, "Software\\NaturalPoint\\NATURALPOINT\\NPClient Location", 0, KEY_READ, &pKey) != ERROR_SUCCESS) { //error condition return NULL; } //********************************************************************** //get the value from the key //*********************************************************************/ if (!pKey) return NULL; //********************************************************************** //first discover the size of the value //*********************************************************************/ if (RegQueryValueEx(pKey, "Path", NULL, NULL, NULL, &dwSize) == ERROR_SUCCESS) { //allocate memory for the buffer for the value szValue = (unsigned char *)malloc(dwSize); if (szValue != NULL) { //********************************************************************** //now get the value //*********************************************************************/ if (RegQueryValueEx(pKey, "Path", NULL, NULL, szValue, &dwSize) == ERROR_SUCCESS) { //everything worked // RegCloseKey(pKey); retval = (char*)szValue; } } } RegCloseKey(pKey); return retval; } //********************************************************************** // Spiffy Macro by wk that retro crippled in order to work in C //*********************************************************************/ #define TEST_RESULT(a, b) \ { if(NP_OK != b) \ { /*::MessageBox(0, a, "", 0);*/\ return; \ } \ } //********************************************************************** // Name: InitTrackIR // Authors: wk, Retro // Date: 26. Feb 2003 // Update: // // Description:Hook up the NaturalPoint game client DLL using the wrapper module //*********************************************************************/ void TrackIR::InitTrackIR(HWND application_window) { unsigned short wNPClientVer; unsigned int DataFields; int TIRVersionMajor = -1, TIRVersionMinor = -1; // not used anyway NPRESULT result; #ifdef DEBUG_TRACKIR_STUFF FILE* fp = fopen("TIR_Debug.txt","at"); fprintf(fp,"Initializing at startup...\n"); if (g_bEnableTrackIR) fprintf(fp,"..with g_bEnableTrackIR ENABLED (of course.. :p)\n"); //if (g_bTrackIR2DCockpit) //{ // fprintf(fp,"Freq %i Yaw %i Pitch %i\n", g_nTrackIRSampleFreq/2, // (int)(g_fTIR2DYawPercentage*(float)16383), // (int)(g_fTIR2DPitchPercentage*(float)16383)); //} fclose(fp); #endif g_bEnableTrackIR = false; // only gets set back to TRUE if init succeeds.. g_bTrackIRon = false; HWND HandleGame = application_window; gcsDLLPath = GetDllLocation(gcsDLLPath); if (!gcsDLLPath) return; //********************************************************************** // Initialize the NPClient interface //*********************************************************************/ TEST_RESULT("NPClient_Init", NPClient_Init(gcsDLLPath)) free ( gcsDLLPath ); // uuurgh.. does this work ? //********************************************************************** // Register the app's window handle //*********************************************************************/ result = NP_RegisterWindowHandle( HandleGame ); if(result != NP_OK) // this happens if the user forgot to start the TrackIR GUI { // do any other error output? // ::MessageBeep(-1); return; } // 2do: NPRESULT __stdcall result = NP_RegisterProgramProfileID(1901); // Falcon ID, issued by Halstead York (NP PR Guru) //********************************************************************** // Query the NaturalPoint software version //*********************************************************************/ result = NP_QueryVersion( &wNPClientVer ); if( NP_OK == result ) { TIRVersionMajor = wNPClientVer >> 8; TIRVersionMinor = wNPClientVer & 0x00FF; }
void FMTest1Thread(TAny* a) { SFMTest1Info& info = *(SFMTest1Info*)a; NThread* pC = NKern::CurrentThread(); TUint32 seed[2] = {(TUint32)pC, 0}; TBool wait = (pC->iPriority > info.iPriorityThreshold); TBool thread0 = (pC==info.iThreads[0]); TInt n = 0; while (!info.iStop) { if (thread0) NKern::ThreadSetPriority(pC, 11); NKern::FMWait(&info.iMutex); TBool ok = verify_block((TUint32*)info.iBlock, info.iBlockSize); TEST_RESULT(ok, "Block corrupt"); ++info.iBlock[0]; setup_block((TUint32*)info.iBlock, info.iBlockSize); ++n; NKern::FMSignal(&info.iMutex); if (wait) { TUint32 x = random(seed) & 1; NKern::Sleep(x+1); } } TEST_PRINT2("Thread %T ran %d times", pC, n); }
Test::TestResult TimeTest::timeMonotonicTest() { const int intervalNanos = 50 * 1000 * 1000; struct timespec interval = { 0, intervalNanos }; const int limitSec = 10 * 60; Util::Timer timer; timer.set(); double prev = timer.get(); while (prev <= limitSec) { nanosleep(&interval, NULL); double curr = timer.get(); if (curr < prev + 1.0e-9 * intervalNanos) { Log::test << "prev=" << prev << '\n'; Log::test << "curr=" << curr << '\n'; return TEST_RESULT(false); } prev = curr; } return TEST_RESULT(true); }
int test_stol() { std::string s1 = "17"; int v1 = std::stoi(s1); TEST_RESULT("stoi", v1, 17); std::string s2 = "701746190"; long v2 = std::stol(s2); TEST_RESULT("stol", v2, 701746190L); std::string s3 = "4611686018427387903"; long long v3 = std::stoll(s3); TEST_RESULT("stol", v3, 4611686018427387903LL); std::string s4 = "701746190"; unsigned long v4 = std::stoul(s4); TEST_RESULT("stoul", v4, 701746190UL); std::string s5 = "4611686018427387903"; long long v5 = std::stoull(s5); TEST_RESULT("stoul", v5, 4611686018427387903ULL); std::string s6 = "1965.58"; float v6 = std::stof(s6); TEST_FLOAT_RESULT("stof", fabsf, float, v6, (float)1965.58); std::string s7 = "1965.58"; double v7 = std::stof(s7); TEST_FLOAT_RESULT("stod", fabs, double, v7, 1965.58); std::string s8 = "1965.58"; long double v8 = std::stold(s8); TEST_FLOAT_RESULT("stold", fabsl, long double, v8, 1965.58); return 0; }
static void task_1_func() { TRACE( "enter\n" ); for( ; task_1_iteration < max_iterations; task_1_iteration++ ) { TRACE( "%d\n", task_1_iteration ); yield(); TRACE( "task_2 is idle here\n" ); tick_handler(); TRACE( "task_2 is ready here; it will run after yield() at the next iteration\n" ); } TRACE( "task_1_iteration=%d, task_2_iteration=%d\n", task_1_iteration, task_2_iteration ); TEST_RESULT( task_1_iteration == max_iterations && task_2_iteration == max_iterations - 1, "task_1_iteration is greater because of post-increment in for() loop" ); }
void FSTest2(TAny* a) { SFSTest2Info& info = *(SFSTest2Info*)a; NFastSemaphore exitSem(0); NKern::FSSetOwner(&info.iSem, 0); info.iBlockCount = 0; info.iWaits = 0; info.iSignals = 0; info.iStart = FALSE; info.iStop = FALSE; TInt cpu; TInt threads = 0; TInt this_cpu = NKern::CurrentCpu(); for_each_cpu(cpu) { if (cpu==this_cpu) CreateThreadSignalOnExit("FSTest2Sig0", &FSTest2Signaller0, 11, a, 0, KSmallTimeslice, &exitSem, cpu); else CreateThreadSignalOnExit("FSTest2Sig", &FSTest2Signaller, 12, a, 0, KSmallTimeslice, &exitSem, cpu); ++threads; } info.iStart = TRUE; while(info.iWaits < 1048576) { NKern::FSWait(&info.iSem); ++info.iWaits; } info.iStop = TRUE; while (threads--) NKern::FSWait(&exitSem); TEST_PRINT1("Leftover signals %d", info.iSignals-info.iWaits); TInt r; do { r = WaitWithTimeout(&info.iSem, KMinTimeout); TEST_RESULT1(r==KErrNone || r==KErrTimedOut, "Invalid return code %d", r); if (r == KErrNone) ++info.iWaits; } while(r == KErrNone); TEST_PRINT2("Signalled %d, Waited %d", info.iSignals, info.iWaits); TEST_RESULT(info.iWaits==info.iSignals, "MISMATCH!"); }
nsresult TextEditorTest::RunUnitTest(int32_t *outNumTests, int32_t *outNumTestsFailed) { nsresult result; NS_ENSURE_TRUE(outNumTests && outNumTestsFailed, NS_ERROR_NULL_POINTER); *outNumTests = 0; *outNumTestsFailed = 0; result = InitDoc(); TEST_RESULT(result); // shouldn't we just bail on error here? // insert some simple text result = mTextEditor->InsertText(NS_LITERAL_STRING("1234567890abcdefghij1234567890")); TEST_RESULT(result); (*outNumTests)++; if (NS_FAILED(result)) ++(*outNumTestsFailed); // insert some more text result = mTextEditor->InsertText(NS_LITERAL_STRING("Moreover, I am cognizant of the interrelatedness of all communities and states. I cannot sit idly by in Atlanta and not be concerned about what happens in Birmingham. Injustice anywhere is a threat to justice everywhere")); TEST_RESULT(result); (*outNumTests)++; if (NS_FAILED(result)) ++(*outNumTestsFailed); result = TestInsertBreak(); TEST_RESULT(result); (*outNumTests)++; if (NS_FAILED(result)) ++(*outNumTestsFailed); result = TestTextProperties(); TEST_RESULT(result); (*outNumTests)++; if (NS_FAILED(result)) ++(*outNumTestsFailed); // get us back to the original document result = mEditor->Undo(12); TEST_RESULT(result); return result; }
void FMTest0() { TEST_PRINT("Testing non-contention case"); NFastMutex m; TEST_RESULT(!m.HeldByCurrentThread(), "Mutex held by current thread"); TEST_RESULT(!NKern::HeldFastMutex(), "Current thread holds a fast mutex"); NKern::FMWait(&m); TEST_RESULT(m.HeldByCurrentThread(), "Mutex not held by current thread"); TEST_RESULT(NKern::HeldFastMutex()==&m, "HeldFastMutex() incorrect"); NKern::FMSignal(&m); TEST_RESULT(!m.HeldByCurrentThread(), "Mutex held by current thread"); TEST_RESULT(!NKern::HeldFastMutex(), "Current thread holds a fast mutex"); }
nsresult TextEditorTest::TestTextProperties() { nsCOMPtr<nsIDOMDocument>doc; nsresult result = mEditor->GetDocument(getter_AddRefs(doc)); TEST_RESULT(result); TEST_POINTER(doc.get()); nsCOMPtr<nsIDOMNodeList>nodeList; // XXX This is broken, text nodes are not elements. nsAutoString textTag(NS_LITERAL_STRING("#text")); result = doc->GetElementsByTagName(textTag, getter_AddRefs(nodeList)); TEST_RESULT(result); TEST_POINTER(nodeList.get()); uint32_t count; nodeList->GetLength(&count); NS_ASSERTION(0!=count, "there are no text nodes in the document!"); nsCOMPtr<nsIDOMNode>textNode; result = nodeList->Item(count-1, getter_AddRefs(textNode)); TEST_RESULT(result); TEST_POINTER(textNode.get()); // set the whole text node to bold printf("set the whole first text node to bold\n"); nsCOMPtr<nsISelection>selection; result = mEditor->GetSelection(getter_AddRefs(selection)); TEST_RESULT(result); TEST_POINTER(selection.get()); nsCOMPtr<nsIDOMCharacterData>textData; textData = do_QueryInterface(textNode); uint32_t length; textData->GetLength(&length); selection->Collapse(textNode, 0); selection->Extend(textNode, length); nsCOMPtr<nsIHTMLEditor> htmlEditor (do_QueryInterface(mTextEditor)); NS_ENSURE_TRUE(htmlEditor, NS_ERROR_FAILURE); bool any = false; bool all = false; bool first=false; const nsAFlatString& empty = EmptyString(); result = htmlEditor->GetInlineProperty(nsGkAtoms::b, empty, empty, &first, &any, &all); TEST_RESULT(result); NS_ASSERTION(false==first, "first should be false"); NS_ASSERTION(false==any, "any should be false"); NS_ASSERTION(false==all, "all should be false"); result = htmlEditor->SetInlineProperty(nsGkAtoms::b, empty, empty); TEST_RESULT(result); result = htmlEditor->GetInlineProperty(nsGkAtoms::b, empty, empty, &first, &any, &all); TEST_RESULT(result); NS_ASSERTION(true==first, "first should be true"); NS_ASSERTION(true==any, "any should be true"); NS_ASSERTION(true==all, "all should be true"); mEditor->DebugDumpContent(); // remove the bold we just set printf("set the whole first text node to not bold\n"); result = htmlEditor->RemoveInlineProperty(nsGkAtoms::b, empty); TEST_RESULT(result); result = htmlEditor->GetInlineProperty(nsGkAtoms::b, empty, empty, &first, &any, &all); TEST_RESULT(result); NS_ASSERTION(false==first, "first should be false"); NS_ASSERTION(false==any, "any should be false"); NS_ASSERTION(false==all, "all should be false"); mEditor->DebugDumpContent(); // set all but the first and last character to bold printf("set the first text node (1, length-1) to bold and italic, and (2, length-1) to underline.\n"); selection->Collapse(textNode, 1); selection->Extend(textNode, length-1); result = htmlEditor->SetInlineProperty(nsGkAtoms::b, empty, empty); TEST_RESULT(result); result = htmlEditor->GetInlineProperty(nsGkAtoms::b, empty, empty, &first, &any, &all); TEST_RESULT(result); NS_ASSERTION(true==first, "first should be true"); NS_ASSERTION(true==any, "any should be true"); NS_ASSERTION(true==all, "all should be true"); mEditor->DebugDumpContent(); // make all that same text italic result = htmlEditor->SetInlineProperty(nsGkAtoms::i, empty, empty); TEST_RESULT(result); result = htmlEditor->GetInlineProperty(nsGkAtoms::i, empty, empty, &first, &any, &all); TEST_RESULT(result); NS_ASSERTION(true==first, "first should be true"); NS_ASSERTION(true==any, "any should be true"); NS_ASSERTION(true==all, "all should be true"); result = htmlEditor->GetInlineProperty(nsGkAtoms::b, empty, empty, &first, &any, &all); TEST_RESULT(result); NS_ASSERTION(true==first, "first should be true"); NS_ASSERTION(true==any, "any should be true"); NS_ASSERTION(true==all, "all should be true"); mEditor->DebugDumpContent(); // make all the text underlined, except for the first 2 and last 2 characters result = doc->GetElementsByTagName(textTag, getter_AddRefs(nodeList)); TEST_RESULT(result); TEST_POINTER(nodeList.get()); nodeList->GetLength(&count); NS_ASSERTION(0!=count, "there are no text nodes in the document!"); result = nodeList->Item(count-2, getter_AddRefs(textNode)); TEST_RESULT(result); TEST_POINTER(textNode.get()); textData = do_QueryInterface(textNode); textData->GetLength(&length); NS_ASSERTION(length==915, "wrong text node"); selection->Collapse(textNode, 1); selection->Extend(textNode, length-2); result = htmlEditor->SetInlineProperty(nsGkAtoms::u, empty, empty); TEST_RESULT(result); result = htmlEditor->GetInlineProperty(nsGkAtoms::u, empty, empty, &first, &any, &all); TEST_RESULT(result); NS_ASSERTION(true==first, "first should be true"); NS_ASSERTION(true==any, "any should be true"); NS_ASSERTION(true==all, "all should be true"); mEditor->DebugDumpContent(); return result; }
void TiedEventTest(TBool aTied, TInt aThreads, TTiedMode aMode) { TEST_PRINT3("TiedEventTest aTied=%d aThreads=%d aMode=%d", aTied, aThreads, aMode); // Set up shared parameters memclr((void*)&Flags,sizeof(Flags)); Done = EFalse; FlagsSet = 0; // Create test threads to check data NFastSemaphore exitSem(0); NFastSemaphore doneSem(0); DoneSem = &doneSem; char name[5]={0x54, 0x45, 0x54, 0x31, 0}; TInt i; NSchedulable* tieTo = NULL; NThread* t[16]; NThreadGroup* group = NULL; if (aThreads == 1) { t[0] = CreateUnresumedThreadSignalOnExit(name, TiedEventThread, 10, NULL, 0, KSmallTimeslice, &exitSem, KCpuAffinityAny); if (aTied) tieTo = t[0]; } else { group = &TG; if (aTied) tieTo = group; SNThreadGroupCreateInfo ginfo; ginfo.iCpuAffinity = KCpuAffinityAny; TInt r = NKern::GroupCreate(group, ginfo); TEST_RESULT(r==KErrNone, "Failed creating group"); for (i=0; i<aThreads; ++i) { t[i] = CreateUnresumedThreadSignalOnExit(name, TiedEventThread, 10, NULL, 0, KSmallTimeslice, &exitSem, KCpuAffinityAny, group); ++name[3]; } } #ifndef __X86__ // Tie the system timer interrupt to the thread if we're testing interrupts // This means the timer function should always be exclusive with the theads // even though it's not tied itself. if (aMode == EInterrupt && tieTo) HijackSystemTimer(tieTo); #endif // Create the IDFC NSchedulable* tieDFC = aMode == EIDFC ? tieTo : NULL; TDfc idfc(tieDFC, FiddleFlags, NULL); IDfc = &idfc; // Create and start NTimer // If we're testing timers it will be tied itself // If we're testing interrupts it will not be tied itself but will still run // exclusively because the interrupt is tied // If we're testing IDFCs it's just used to repeatedly queue the IDFC and // where the timer itself runs is irrelevant. NSchedulable* tieTimer = aMode == ETimer ? tieTo : NULL; NTimerFn timerfn = aMode == EIDFC ? IDfcQFn : TimerFn; NTimer timer(tieTimer, timerfn, NULL); Timer = &timer; timer.OneShot(10); // Resume threads for (i=0; i<aThreads; ++i) NKern::ThreadResume(t[i]); // Wait for threads to be done for (i=0; i<aThreads; ++i) NKern::FSWait(&doneSem); // Tell timer to stop requeueing itself __e32_atomic_store_rel32(&Done, ETrue); NKern::Sleep(100); #ifndef __X86__ // Restart the normal system timer if we're testing interrupts // as otherwise it will get unbound when the thing it's tied to // dies. if (aMode == EInterrupt && tieTo) HijackSystemTimer(NULL); #endif // Clean up threads/group for (i=0; i<aThreads; ++i) { NKern::ThreadRequestSignal(t[i]); NKern::FSWait(&exitSem); } if (group) NKern::GroupDestroy(group); // Check that the flag was ok TEST_PRINT1("Flag was set %d times", FlagsSet); if (aTied) TEST_RESULT(FlagsSet == 0, "Flag was set, shouldn't be"); else TEST_RESULT(FlagsSet > 0, "Flag wasn't set, test broken?"); }