Пример #1
0
static void __stdcall gsplittest()
{
	CString m;
	m.Format(_T("%s,%i,%i,,%f,%i,,%f,%f,%i,%i,,,%i"),"TST",10,100,0,0,0,0,0,0,0);

	vector<CString> r;
	gsplit(m,CString(","),r);
	CFIX_ASSERT(r.size()==14);

	// performance test
	const int MAXGSPLITS = 1000;
	vector<CString> strs;
	// start timer
	unsigned long start = GetTickCount();
	// split strings
	for (int i = 0; i<MAXGSPLITS; i++)
	{
		m.Format(_T("%s,%i,%i,,%f,%i,,%f,%f,%i,%i,,,%i"),"TST",rand(),100,0,0,0,0,0,0,0);
		vector<CString> r2;
		gsplit(m,CString(","),r2);
	}
	// stop timer
	unsigned long stop = GetTickCount();
	// elapsed
	int elapms = stop - start;
	int rate = elapms== 0 ? 0 : (MAXGSPLITS/elapms)*1000;
	CFIX_LOG(L"Gsplit elapsed time(ms): %i",elapms);
	CFIX_LOG(L"Gsplits perf (splits/sec: %i",rate);
	CFIX_ASSERT(elapms<50);
}
Пример #2
0
static VOID LogAndFailAtPassiveLevelAndAbort()
{
	CFIX_ASSERT( "Truth" );
	CFIX_LOG( L"" );
	CFIX_LOG( L"" );
	CFIX_ASSERT( !"Untruth" );
	ASSERT( !"Should not make it here!" );
}
  void TransformOK()
  {
	HTTPS::Rules rules;
	HRESULT hr = rules.Add("default.rulesets");

	char* url = "http://www.1and1.com/index.html";
	char* newURL = rules.Transform(url);
	CFIX_ASSERT( newURL != NULL );

	CFIX_LOG("New URL: %s", newURL);

	CFIX_ASSERT( strcmp("https://order.1and1.com/index.html", newURL) == 0 );

	delete newURL;
  }
  void MatchOK() 
  {
	HTTPS::Securecookies cookies("^.*\\.google\\.com$", ".+");
	bool match = cookies.IsMatch("www.google.com", "foo");

	CFIX_ASSERT(match);
  }
    void MatchFail1() 
  {
	HTTPS::Securecookies cookies("^.*\\.google\\.com$", "bar");
	bool match = cookies.IsMatch("www.google.com", "foo");

	CFIX_ASSERT(match == false);
  }
Пример #6
0
  void IntTraits()
  {
    ObjectTraits<int> intTraits;

    int here = 1234;
    int* where = intTraits.addressOf(here);
    CFIX_ASSERT(where == &here);

    int const& hereConst = here;
    int const* whereConst = intTraits.addressOf(hereConst);
    CFIX_ASSERT(whereConst == &hereConst && whereConst == &here);

    int newInt = 10;
    int anInt = 100;
    intTraits.construct(&newInt, anInt);
    CFIX_ASSERT(anInt == 100);
  }
  void HostMatchOK() 
  {
	HTTPS::Rules rules;
	HRESULT hr = rules.Add("default.rulesets");
	bool match = rules.HostMatch("www.google.com");

	CFIX_ASSERT(match);
  }
Пример #8
0
static VOID LogThreeMessagesAtPassiveLevel()
{
	CFIX_ASSERT( "Truth" );

	CFIX_LOG( L"Log at %s", L"PASSIVE_LEVEL" );
	CFIX_LOG( L"Log at %s", L"PASSIVE_LEVEL" );
	CFIX_LOG( L"Log at %s", L"PASSIVE_LEVEL" );
}
  void HostMatchFail() 
  {
		HTTPS::Rules rules;
		HRESULT hr = rules.Add("default.rulesets");
		bool match = rules.HostMatch("foo.www.google.com.sobrier.net");

		CFIX_ASSERT( match == false );
  }
Пример #10
0
static VOID LogAndFailAtDirqlAndAbort()
{
	KIRQL Irql;
	KeRaiseIrql( DISPATCH_LEVEL + 1, &Irql );
	CFIX_ASSERT( "Truth" );
	CFIX_LOG( L"" );
	CFIX_ASSERT_EQUALS_ULONG( 1, 2 );
	ASSERT( !"Should not make it here!" );
}
Пример #11
0
void FailingTestAtElevatedIrql()
{
	KIRQL OldIrql;
	KeRaiseIrql( DISPATCH_LEVEL, &OldIrql );
	CFIX_LOG( L"Test" );
	CFIX_ASSERT( !"Fail" );
	CFIX_LOG( L"?" );
	KeLowerIrql( OldIrql );
}
Пример #12
0
void ListModulesExpectOverflow()
{
	HANDLE Dev;
	DWORD Cb;
	CFIXKR_IOCTL_GET_MODULES Res;
	
	CFIX_ASSERT_EQUALS_DWORD( ERROR_SUCCESS, LoadReflector() );
	CFIX_ASSERT_EQUALS_DWORD( ERROR_SUCCESS, LoadDriver( L"testklib1", L"testklib1.sys" ) );
	CFIX_ASSERT_EQUALS_DWORD( ERROR_SUCCESS, LoadDriver( L"testklib2", L"testklib2.sys" ) );
	__try
	{
		Dev = CreateFile(
			L"\\\\.\\Cfixkr",
			GENERIC_READ | GENERIC_WRITE,
			0,
			NULL,
			OPEN_EXISTING,
			FILE_ATTRIBUTE_NORMAL,
			NULL );
		CFIX_ASSERT( Dev != INVALID_HANDLE_VALUE );

		CFIX_ASSERT( ! DeviceIoControl(
			Dev,
			CFIXKR_IOCTL_GET_TEST_MODULES,
			NULL,
			0,
			&Res,
			sizeof( Res ),
			&Cb,
			NULL ) );
		CFIX_ASSERT_EQUALS_DWORD( ERROR_MORE_DATA, GetLastError() );
		CFIX_ASSERT( CloseHandle( Dev ) );
		CFIX_ASSERT_EQUALS_DWORD( sizeof( Res ), Cb );
		CFIX_ASSERT_EQUALS_DWORD( 2, Res.Count );
		CFIX_ASSERT( Res.DriverLoadAddress[ 0 ] & 0x80000000 );
		CFIX_ASSERT( ( Res.DriverLoadAddress[ 0 ] & 0x00000FFF ) == 0 );
	}
	__finally
	{
		UnloadDriver( L"cfixkr" );
		UnloadDriver( L"testklib1" );
		UnloadDriver( L"testklib2" );
	}
}
  void ExclusionTransform1()
  {
	HTTPS::Rules rules;
	HRESULT hr = rules.Add("default.rulesets");

	char* url = "http://via.me.s3.amazonaws.com/";
	char* newURL = rules.Transform(url);

	CFIX_ASSERT( newURL != NULL );
  }
Пример #14
0
static VOID EnumRemoveCallback(
	__in PJPHT_HASHTABLE Hashtable,
	__in PJPHT_HASHTABLE_ENTRY Entry,
	__in_opt PVOID Context
	)
{
	PJPHT_HASHTABLE_ENTRY OldEntry;
	UNREFERENCED_PARAMETER( Context );
	JphtRemoveEntryHashtable( Hashtable, Entry->Key, &OldEntry );
	CFIX_ASSERT( OldEntry == Entry );
}
Пример #15
0
/*++
	Routine Description:
		Test routine -- do the actual testing.
--*/
static void __stdcall Test1()
{
	DWORD a = 1;
	DWORD b = 1;
	CFIX_ASSERT_EQUALS_DWORD( a, b );
	CFIX_ASSERT( a + b == 2 );

	//
	// Log a message -- printf-style formatting may be used.
	//
	CFIX_LOG( L"a=%d, b=%d", a, b );
}
Пример #16
0
/*++
	Routine Description:
		Another test routine -- one that will trigger a failed 
		assertion.
--*/
static void __stdcall Test2()
{
	DWORD a = 17;

	CFIX_ASSERT( a == 17 );

	//
	// This one will fail. If run in the debugger, it will break here.
	// if run outside the debugger, the failure will be logged and the
	// testcase is aborted.
	//
	//CFIX_ASSERT( a == 42 );
}
Пример #17
0
static VOID LogThreeMessagesAtDirql()
{
	KIRQL Irql;
	KeRaiseIrql( DISPATCH_LEVEL + 1, &Irql );
	
	CFIX_ASSERT( "Truth" );

	CFIX_LOG( L"Log at %s", L"elevated irql" );
	CFIX_LOG( L"Log at %s", L"elevated irql" );
	CFIX_LOG( L"Log at %s", L"elevated irql" );

	KeLowerIrql( Irql );
}
Пример #18
0
void ListModulesInvalidRequestSize()
{
	HANDLE Dev;
	DWORD Cb;
	ULONG Req;
	CFIXKR_IOCTL_GET_MODULES Res;
	
	CFIX_ASSERT_EQUALS_DWORD( ERROR_SUCCESS, LoadReflector() );
	__try
	{
		Dev = CreateFile(
			L"\\\\.\\Cfixkr",
			GENERIC_READ | GENERIC_WRITE,
			0,
			NULL,
			OPEN_EXISTING,
			FILE_ATTRIBUTE_NORMAL,
			NULL );
		CFIX_ASSERT( Dev != INVALID_HANDLE_VALUE );

		CFIX_ASSERT( ! DeviceIoControl(
			Dev,
			CFIXKR_IOCTL_GET_TEST_MODULES,
			&Req,
			sizeof( ULONG ),	// should be 0.
			&Res,
			sizeof( CFIXKR_IOCTL_GET_MODULES ),
			&Cb,
			NULL ) );
		CFIX_ASSERT_EQUALS_DWORD( ERROR_INVALID_PARAMETER, GetLastError() );
		CFIX_ASSERT( CloseHandle( Dev ) );
	}
	__finally
	{
		UnloadDriver( L"cfixkr" );
	}
}
Пример #19
0
void ListModulesExpectEmptyResponse()
{
	HANDLE Dev;
	DWORD Cb;
	CFIXKR_IOCTL_GET_MODULES Res;
	
	CFIX_ASSERT_EQUALS_DWORD( ERROR_SUCCESS, LoadReflector() );
	__try
	{
		Dev = CreateFile(
			L"\\\\.\\Cfixkr",
			GENERIC_READ | GENERIC_WRITE,
			0,
			NULL,
			OPEN_EXISTING,
			FILE_ATTRIBUTE_NORMAL,
			NULL );
		CFIX_ASSERT( Dev != INVALID_HANDLE_VALUE );

		CFIX_ASSERT( DeviceIoControl(
			Dev,
			CFIXKR_IOCTL_GET_TEST_MODULES,
			NULL,
			0,
			&Res,
			sizeof( CFIXKR_IOCTL_GET_MODULES ),
			&Cb,
			NULL ) );
		CFIX_ASSERT( CloseHandle( Dev ) );
		CFIX_ASSERT( Cb == sizeof( ULONG ) );
		CFIX_ASSERT( Res.Count == 0 );
	}
	__finally
	{
		UnloadDriver( L"cfixkr" );
	}
}
Пример #20
0
static void LogAndFailAtPassiveLevelOnChildThreadAndAbort()
{
	OBJECT_ATTRIBUTES ObjectAttributes;
	HANDLE Thread;

	InitializeObjectAttributes(
		&ObjectAttributes, 
		NULL, 
		OBJ_KERNEL_HANDLE, 
		NULL, 
		NULL );

	CFIX_ASSERT( STATUS_SUCCESS == CfixCreateSystemThread(
		&Thread,
		THREAD_ALL_ACCESS,
		&ObjectAttributes,
		NULL,
		NULL,
		LogAndFailAtPassiveLevelOnChildThreadAndAbortThreadProc,
		NULL,
		0 ) );
	CFIX_ASSERT( Thread );
	CFIX_ASSERT( NT_SUCCESS( ZwClose( Thread ) ) );
}
Пример #21
0
DWORD LoadReflector()
{
	SYSTEM_INFO SystemInfo;

	CfixklGetNativeSystemInfo( &SystemInfo );
	switch ( SystemInfo.wProcessorArchitecture  )
	{
	case PROCESSOR_ARCHITECTURE_INTEL:
		return LoadDriver( L"cfixkr", L"cfixkr32.sys" );

	case PROCESSOR_ARCHITECTURE_AMD64:
		return LoadDriver( L"cfixkr", L"cfixkr64.sys" );

	default:
		CFIX_ASSERT( !"Unsupported processor architecture" );
		return ERROR_FUNCTION_FAILED;
	}
}
Пример #22
0
static VOID LogAndInconclusiveAtDirql()
{
	KIRQL Irql;
	KeRaiseIrql( DISPATCH_LEVEL + 1, &Irql );
	
	CFIX_ASSERT( "Truth" );

	CFIX_LOG( L"Log at %s", L"PASSIVE_LEVEL" );

	//
	// Note: message is of same length as IRQL-warning. Important
	// as both compete for the same buffer space.
	//
	CFIX_INCONCLUSIVE( L"Inconclusive   "
		L"01234567890123456789012345678901234567890123456789"
		L"01234567890123456789012345678901234567890123456789" );
	ASSERT( !"Should not make it here!" );
}
Пример #23
0
    /**-------------------------------------------------------------------------------
    	TestOne

    	@brief
    	@return void
    ---------------------------------------------------------------------------------*/
    void TestOne()
    {
        const wchar_t* testString = L"test model";
        CFIX_LOG(L"Testing %s", testString);

        // samples
        CFIXCC_ASSERT_EQUALS(1, 1);
        CFIXCC_ASSERT_EQUALS(L"test model", testString);
        CFIXCC_ASSERT_EQUALS(wcslen(testString), (size_t) 10);
        CFIX_ASSERT(wcslen(testString) == 10);
        CFIX_ASSERT_MESSAGE(testString[0] == 't', "Test string should start with a 't'");


        double expected[]= {0,1.000000000000000,0.500000000000000,0.750000000000000,0.625000000000000,0.687500000000000,0.656250000000000,0.671875000000000,0.664062500000000,0.667968750000000,0.666015625000000,0.666992187500000,0.666503906250000,0.666748046875000,0.666625976562500,0.666687011718750,0.666656494140625};

        for (int i=0; i<17; ++i) {
            double out=getSystemOutput(1);
            CFIXCC_ASSERT_EQUALS(expected[i], out);
        }

    }
Пример #24
0
  void ClassTraits()
  {
    ObjectTraits<TestObject> testObjectTraits;

    TestObject here;
    TestObject* where = testObjectTraits.addressOf(here);
    CFIX_ASSERT(where == &here);

    TestObject const& hereConst = here;
    TestObject const* whereConst = testObjectTraits.addressOf(hereConst);
    CFIX_ASSERT(whereConst == &hereConst && whereConst == &here);

    TestObject newObject;
    CFIX_ASSERT(newObject.constructionCount == 2);

    TestObject anObject;
    CFIX_ASSERT(anObject.constructionCount == 3);

    testObjectTraits.construct(&newObject, anObject);
    CFIX_ASSERT(newObject.constructionCount == 3);

    testObjectTraits.destroy(&newObject);
    CFIX_ASSERT(newObject.destructed == true);
  }
Пример #25
0
	void Method01() 
	{
		CFIX_ASSERT( setupCalled );
		CFIXCC_ASSERT_EQUALS( counter, 1 );
		counter++;
	}
Пример #26
0
	static void SetUp()
	{
		CFIX_ASSERT( ! setupCalled );
		setupCalled = true;
	}
Пример #27
0
	static void TearDown()
	{
		CFIX_ASSERT( setupCalled );
	}
Пример #28
0
	virtual void Before()
	{
		CFIX_ASSERT( setupCalled );
		CFIXCC_ASSERT_EQUALS( counter, 0 );
		counter++;
	}
Пример #29
0
/*++
	Routine Description:
		Setup Routine -- will be called at the very beginning of the
		testrun. If the setup routine fails, no testcase of this 
		fixture will be executed.

		If your default calling convention is cdecl (this is the 
		case for Visual Studio projects), be sure to add __stdcall 
		to all routine decarations -- otheriwse you will get the 
		following warning:
		   cannot convert from 'void (__cdecl *)(void)' 
		   to 'CFIX_PE_TESTCASE_ROUTINE'

		As the routine is referenced only by the fixture definition 
		(see below), you may declare this routine as static.
--*/
static void __stdcall FixtureSetup()
{
	CFIX_ASSERT( 0 != 1 );
}
Пример #30
0
    /**-------------------------------------------------------------------------------
    	TestTwo

    	@brief
    	@return void
    ---------------------------------------------------------------------------------*/
    void TestTwo()
    {

        getSystemOutput(0,true);

        const double PIDexpected[]= {
            0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
            0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
            0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
            0, 0, 0.150000000000000, 0.125000000000000, 0.180000000000000, 0.181250000000000, 0.224125000000000,
            0.238125000000000, 0.269793750000000, 0.287765625000000, 0.313890000000000, 0.333272656250000,
            0.356089640625000, 0.375405078125000, 0.396004611718750, 0.414652892578125, 0.433596977812500,
            0.451332337207031, 0.468919980533203, 0.485665133486328, 0.502073022043652, 0.517827056758057,
            0.533171873003359, 0.547967323187073, 0.562335600973608, 0.576218614296456, 0.589680782567980,
            0.602701939938742, 0.615319020792677, 0.627529166541620, 0.639356026890439, 0.650804430303555,
            0.661891412677581, 0.672625013940508, 0.683018802333854, 0.693081959202753, 0.702826080525318,
            0.712260543064563, 0.721395692081785, 0.730240678287689, 0.738804954326723, 0.747097267491099,
            0.755126364571985, 0.762900525053083, 0.770427895267497, 0.777716274199548, 0.784773273922038,
            0.791606223329374, 0.798222247036399, 0.804628224044169, 0.810830828247730, 0.816836512573039,
            0.822651531297221, 0.828281935886121, 0.833733588594279, 0.839012163573476, 0.844123156195273,
            0.849071886434885, 0.853863506007396, 0.858503002637217, 0.862995205997976, 0.867344792228484,
            0.871556289150349, 0.875634080741917, 0.879582411865564, 0.883405392574458, 0.887107002467577,
            0.890691094779930, 0.894161400429485, 0.897521531876399, 0.900774986900232, 0.903925152229540,
            0.906975307075183, 0.909928626538501, 0.912788184920152, 0.915556958917837, 0.918237830726655,
            0.920833591038189, 0.923346941946321, 0.925780499759464, 0.928136797724423, 0.930418288663157,
            0.932627347526255, 0.934766273865052, 0.936837294225467, 0.938842564465697, 0.940784172000429,
            0.942664137973737, 0.944484419363038, 0.946246911016228, 0.947953447624150, 0.949605805630448,
            0.951205705080773, 0.952754811413295, 0.954254737192366, 0.955707043787133, 0.957113242996879,
            0.958474798624742, 0.959793128001490, 0.961069603460905, 0.962305553768336, 0.963502265503901,
            0.964660984401760, 0.965782916646892, 0.966869230130682, 0.967921055666656, 0.968939488167622,
            0.969925587785427, 0.970880381014546, 0.971804861760619, 0.972699992375075, 0.973566704656904,
            0.974405900822628, 0.975218454445475, 0.976005211364738, 0.976766990566260, 0.977504585034977,
            0.978218762580379, 0.978910266635777, 0.979579817032188, 0.980228110747654, 0.980855822632771,
            0.981463606113189, 0.982052093869795, 0.982621898497321, 0.983173613142026, 0.983707812119147,
            0.984225051510732, 0.984725869744512, 0.985210788154374, 0.985680311523058, 0.986134928607620,
            0.986575112648200, 0.987001321860660, 0.987413999913564, 0.987813576390021, 0.988200467234868,
            0.988575075187653, 0.988937790201872, 0.989288989850895, 0.989629039721011, 0.989958293791987,
            0.990277094805546, 0.990585774622155, 0.990884654566476, 0.991174045761852, 0.991454249454179,
            0.991725557325491, 0.991988251797589, 0.992242606326033, 0.992488885684800, 0.992727346241905,
            0.992958236226268, 0.993181795986115, 0.993398258239167, 0.993607848314899, 0.993810784389090,
            0.994007277710945, 0.994197532822990, 0.994381747774000, 0.994560114325160, 0.994732818149676,
            0.994900039026059, 0.995061951025268, 0.995218722691909, 0.995370517219686, 0.995517492621281,
            0.995659801892836, 0.995797593173217, 0.995931009898225, 0.996060190949905, 0.996185270801115,
            0.996306379655514, 0.996423643583091, 0.996537184651406, 0.996647121052654, 0.996753567226702,
            0.996856633980214, 0.996956428601998, 0.997053054974690, 0.997146613682893, 0.997237202117879,
            0.997324914578972, 0.997409842371711, 0.997492073902894, 0.997571694772608, 0.997648787863332,
            0.997723433426221, 0.997795709164639, 0.997865690315046, 0.997933449725322, 0.997999057930590,
            0.998062583226649, 0.998124091741062, 0.998183647501997, 0.998241312504870, 0.998297146776892,
            0.998351208439545, 0.998403553769086, 0.998454237255136, 0.998503311657392, 0.998550828060553
        };

        double Kp = 0.1, Ti = 0.02, Td = 0.01;
        int type = 0;
        Controller<double>* controller = new ControllerPID(Kp, Ti, Td, 0);

        const float td=0.01f;
        double y=0;
        int i=0;

        for (float t=0.01f; t<3.0f; t+=td) {
            if (t<1) {
                controller->setSetpoint(0.0);
            } else {
                controller->setSetpoint(1.0);
            }

            controller->setInput(y);
            controller->calculate(0.01);
            double out;
            controller->getOutput(out);
            y=getSystemOutput(out);

            //CFIX_LOG(L"%d",i);
            CFIX_ASSERT(fabs(PIDexpected[i]-y)<1e-8);
            ++i;
        }

        delete controller;
    }