static void runChprintfTest() {
	static MemoryStream ts;
	static char testBuffer[200];
	msObjectInit(&ts, (uint8_t *) testBuffer, sizeof(testBuffer), 0);


// it's a very, very long and mostly forgotten story how this became our %.2f precision format
	ts.eos = 0; // reset
	chprintf((BaseSequentialStream*)&ts, "%.2f/%.4f/%.4f", 0.239f, 239.932, 0.1234);
	ts.buffer[ts.eos] = 0;

	assertString(testBuffer, "0.23/239.9320/0.1234");


	{
		LoggingWithStorage testLogging("test");
		appendFloat(&testLogging, 1.23, 5);
		appendFloat(&testLogging, 1.234, 2);
		assertString(testLogging.buffer, "1.230001.23");

	}

	{
		LoggingWithStorage testLogging("test");
		appendFloat(&testLogging, -1.23, 5);
		assertString(testLogging.buffer, "-1.23000");
	}
	{
		LoggingWithStorage testLogging("test");
		appendPrintf(&testLogging, "a%.2fb%fc", -1.2, -3.4);
		assertString(testLogging.buffer, "a-1.20b-3.400000095c");
	}

}
void NamesAndTypesList::readText(ReadBuffer & buf)
{
    const DataTypeFactory & data_type_factory = DataTypeFactory::instance();

    assertString("columns format version: 1\n", buf);
    size_t count;
    DB::readText(count, buf);
    assertString(" columns:\n", buf);
    resize(count);
    for (NameAndTypePair & it : *this)
    {
        readBackQuotedStringWithSQLStyle(it.name, buf);
        assertChar(' ', buf);
        String type_name;
        readString(type_name, buf);
        it.type = data_type_factory.get(type_name);
        assertChar('\n', buf);
    }
}
void _cdecl WinAssert(char * text, char * filename, int linenum, const char * format, ... )
{
	int val;
	va_list args;

	memset( AssertText1, 0, sizeof(AssertText1) );
	memset( AssertText2, 0, sizeof(AssertText2) );

	va_start(args, format);
	vsnprintf(AssertText2, sizeof(AssertText2)-1, format, args);
	va_end(args);

	// this stuff migt be really useful for solving bug reports and user errors. We should output it! 
	mprintf(("ASSERTION: \"%s\" at %s:%d\n %s\n", text, strrchr(filename, '\\')+1, linenum, AssertText2 ));

#ifdef Allow_NoWarn
	if (Cmdline_nowarn) {
		return;
	}
#endif

	Messagebox_active = true;

	gr_activate(0);

	filename = strrchr(filename, '\\')+1;
	snprintf( AssertText1, sizeof(AssertText1)-1, "Assert: %s\r\nFile: %s\r\nLine: %d\r\n%s\r\n", text, filename, linenum, AssertText2 );

#if defined( SHOW_CALL_STACK ) && defined( PDB_DEBUGGING )
	/* Dump the callstack */
	SCP_DebugCallStack callStack;
	SCP_DumpStack( dynamic_cast< SCP_IDumpHandler* >( &callStack ) );
	
	/* Format the string */
	SCP_string assertString( AssertText1 );
	assertString += "\n";
	assertString += callStack.DumpToString( );
	
	/* Copy to the clipboard */
	dump_text_to_clipboard( assertString.c_str( ) );

	// truncate text
	truncate_message_lines(assertString, Messagebox_lines);

	assertString += "\n[ This info is in the clipboard so you can paste it somewhere now ]\n";
	assertString += "\n\nUse Ok to break into Debugger, Cancel to exit.\n";
	val = MessageBox( NULL, assertString.c_str( ), "Assertion Failed!", MB_OKCANCEL | flags );

#elif defined ( SHOW_CALL_STACK	)
	dumpBuffer.Clear();
	dumpBuffer.Printf( AssertText1 );
	dumpBuffer.Printf( "\r\n" );
	DumpCallsStack( dumpBuffer ) ;  
	dump_text_to_clipboard(dumpBuffer.buffer);

	// truncate text
	dumpBuffer.TruncateLines(Messagebox_lines);

	dumpBuffer.Printf( "\r\n[ This info is in the clipboard so you can paste it somewhere now ]\r\n" );
	dumpBuffer.Printf( "\r\n\r\nUse Ok to break into Debugger, Cancel to exit.\r\n");

	val = MessageBox(NULL, dumpBuffer.buffer, "Assertion Failed!", MB_OKCANCEL|flags );
#else
	val = MessageBox(NULL, AssertText1, "Assertion Failed!", MB_OKCANCEL|flags );
#endif

	if (val == IDCANCEL)
		exit(1);

	Int3();

	gr_activate(1);

	Messagebox_active = false;
}
void _cdecl Warning( char *filename, int line, const char *format, ... )
{
	Global_warning_count++;

#ifndef NDEBUG
	va_list args;
	int result;
	int i;
	int slen = 0;

	// output to the debug log before anything else (so that we have a complete record)

	memset( AssertText1, 0, sizeof(AssertText1) );
	memset( AssertText2, 0, sizeof(AssertText2) );

	va_start(args, format);
	vsnprintf(AssertText1, sizeof(AssertText1) - 1, format, args);
	va_end(args);

	slen = strlen(AssertText1);

	// strip out the newline char so the output looks better
	for (i = 0; i < slen; i++){
		if (AssertText1[i] == (char)0x0a) {
			AssertText2[i] = ' ';
		} else {
			AssertText2[i] = AssertText1[i];
		}
	}

	// kill off extra white space at end
	if (AssertText2[slen-1] == (char)0x20) {
		AssertText2[slen-1] = '\0';
	} else {
		// just being careful
		AssertText2[slen] = '\0';
	}

	mprintf(("WARNING: \"%s\" at %s:%d\n", AssertText2, strrchr(filename, '\\')+1, line));

	// now go for the additional popup window, if we want it ...
#ifdef Allow_NoWarn
	if (Cmdline_nowarn) {
		return;
	}
#endif

	filename = strrchr(filename, '\\')+1;
	sprintf(AssertText2, "Warning: %s\r\nFile: %s\r\nLine: %d\r\n", AssertText1, filename, line );

	Messagebox_active = true;

	gr_activate(0);

#if defined( SHOW_CALL_STACK ) && defined( PDB_DEBUGGING )
	/* Dump the callstack */
	SCP_DebugCallStack callStack;
	SCP_DumpStack( dynamic_cast< SCP_IDumpHandler* >( &callStack ) );
	
	/* Format the string */
	SCP_string assertString( AssertText1 );
	assertString += "\n";
	assertString += callStack.DumpToString( );
	
	/* Copy to the clipboard */
	dump_text_to_clipboard( assertString.c_str( ) );

	// truncate text
	truncate_message_lines(assertString, Messagebox_lines);

	assertString += "\n[ This info is in the clipboard so you can paste it somewhere now ]\n";
	assertString += "\n\nUse Yes to break into Debugger, No to continue.\nand Cancel to Quit\n";
	result = MessageBox( NULL, assertString.c_str( ), "Warning!", MB_YESNOCANCEL | MB_DEFBUTTON2 | MB_ICONWARNING | flags );

#elif defined ( SHOW_CALL_STACK	)
	//we don't want to dump the call stack for every single warning
	Dump_to_log = false; 

	dumpBuffer.Clear();
	dumpBuffer.Printf( AssertText2 );
	dumpBuffer.Printf( "\r\n" );
	DumpCallsStack( dumpBuffer ) ;  
	dump_text_to_clipboard(dumpBuffer.buffer);

	// truncate text
	dumpBuffer.TruncateLines(Messagebox_lines);

	dumpBuffer.Printf( "\r\n[ This info is in the clipboard so you can paste it somewhere now ]\r\n" );
	dumpBuffer.Printf("\r\n\r\nUse Yes to break into Debugger, No to continue.\r\nand Cancel to Quit");

	result = MessageBox((HWND)os_get_window(), dumpBuffer.buffer, "Warning!", MB_YESNOCANCEL | MB_DEFBUTTON2 | MB_ICONWARNING | flags );

	Dump_to_log = true; 

#else
	strcat_s(AssertText2,"\r\n\r\nUse Yes to break into Debugger, No to continue.\r\nand Cancel to Quit");
	result = MessageBox((HWND)os_get_window(), AssertText2, "Warning!", MB_YESNOCANCEL | MB_DEFBUTTON2 | MB_ICONWARNING | flags );
#endif

	switch (result)
	{
		case IDYES:
			Int3();
			break;

		case IDNO:
			break;

		case IDCANCEL:
			exit(1);
	}

	gr_activate(1);

	Messagebox_active = false;
#endif // !NDEBUG
}
void _cdecl Error( const char * filename, int line, const char * format, ... )
{
	Global_error_count++;

	int val;
	va_list args;

	memset( AssertText1, 0, sizeof(AssertText1) );
	memset( AssertText2, 0, sizeof(AssertText2) );

	va_start(args, format);
	vsnprintf(AssertText1, sizeof(AssertText1)-1, format, args);
	va_end(args);

	filename = strrchr(filename, '\\')+1;
	snprintf(AssertText2, sizeof(AssertText2)-1, "Error: %s\r\nFile: %s\r\nLine: %d\r\n", AssertText1, filename, line);
	mprintf(("ERROR: %s\r\nFile: %s\r\nLine: %d\r\n", AssertText1, filename, line));

	Messagebox_active = true;

	gr_activate(0);

#if defined( SHOW_CALL_STACK ) && defined( PDB_DEBUGGING )
	/* Dump the callstack */
	SCP_DebugCallStack callStack;
	SCP_DumpStack( dynamic_cast< SCP_IDumpHandler* >( &callStack ) );
	
	/* Format the string */
	SCP_string assertString( AssertText1 );
	assertString += "\n";
	assertString += callStack.DumpToString( );
	
	/* Copy to the clipboard */
	dump_text_to_clipboard( assertString.c_str( ) );

	// truncate text
	truncate_message_lines(assertString, Messagebox_lines);

	assertString += "\n[ This info is in the clipboard so you can paste it somewhere now ]\n";
	assertString += "\n\nUse Ok to break into Debugger, Cancel to exit.\n";
	val = MessageBox( NULL, assertString.c_str( ), "Error!", flags | MB_DEFBUTTON2 | MB_OKCANCEL );

#elif defined( SHOW_CALL_STACK )
	dumpBuffer.Clear();
	dumpBuffer.Printf( AssertText2 );
	dumpBuffer.Printf( "\r\n" );
	DumpCallsStack( dumpBuffer ) ;  
	dump_text_to_clipboard(dumpBuffer.buffer);

	// truncate text
	dumpBuffer.TruncateLines(Messagebox_lines);

	dumpBuffer.Printf( "\r\n[ This info is in the clipboard so you can paste it somewhere now ]\r\n" );
	dumpBuffer.Printf( "\r\n\r\nUse Ok to break into Debugger, Cancel exits.\r\n");

	val = MessageBox(NULL, dumpBuffer.buffer, "Error!", flags | MB_DEFBUTTON2 | MB_OKCANCEL );
#else
	strcat_s(AssertText2,"\r\n\r\nUse Ok to break into Debugger, Cancel exits.\r\n");

	val = MessageBox(NULL, AssertText2, "Error!", flags | MB_DEFBUTTON2 | MB_OKCANCEL );
#endif

	switch (val)
	{
		case IDCANCEL:
			exit(1);

		default:
			Int3();
			break;
	}

	gr_activate(1);

	Messagebox_active = false;
}
Exemple #6
0
void _cdecl WinAssert(char* text, char* filename, int linenum)
{
	int val;

	// this stuff migt be really useful for solving bug reports and user errors. We should output it! 
	mprintf(("ASSERTION: \"%s\" at %s:%d\n", text, strrchr(filename, '\\') + 1, linenum));

	if (Cmdline_nowarn)
		return;

	Messagebox_active = true;

	gr_activate(0);

	filename = strrchr(filename, '\\') + 1;
	sprintf(AssertText1, "Assert: %s\r\nFile: %s\r\nLine: %d\r\n", text, filename, linenum);

#if defined( SHOW_CALL_STACK ) && defined( PDB_DEBUGGING )
	/* Dump the callstack */
	SCP_DebugCallStack callStack;
	SCP_DumpStack( dynamic_cast< SCP_IDumpHandler* >( &callStack ) );

	/* Format the string */
	std::string assertString( AssertText1 );
	assertString += "\n";
	assertString += callStack.DumpToString( );

	/* Copy to the clipboard */
	dump_text_to_clipboard( assertString.c_str( ) );

	assertString += "\n[ This info is in the clipboard so you can paste it somewhere now ]\n";
	assertString += "\n\nUse Ok to break into Debugger, Cancel to exit.\n";
	val = MessageBox( NULL, assertString.c_str( ), "Assertion Failed!", MB_OKCANCEL | flags );

#elif defined( SHOW_CALL_STACK )
	dumpBuffer.Clear();
	dumpBuffer.Printf( AssertText1 );
	dumpBuffer.Printf( "\r\n" );
	DumpCallsStack( dumpBuffer ) ;
	dump_text_to_clipboard(dumpBuffer.buffer);

	dumpBuffer.Printf( "\r\n[ This info is in the clipboard so you can paste it somewhere now ]\r\n" );
	dumpBuffer.Printf( "\r\n\r\nUse Ok to break into Debugger, Cancel to exit.\r\n");

	val = MessageBox(NULL, dumpBuffer.buffer, "Assertion Failed!", MB_OKCANCEL|flags );
#else
	val = MessageBox(NULL, AssertText1, "Assertion Failed!", MB_OKCANCEL | flags);
#endif

	if (val == IDCANCEL)
		exit(1);
#ifndef INTERPLAYQA
	Int3();
#else
	AsmInt3();
#endif

	gr_activate(1);

	Messagebox_active = false;
}
Exemple #7
0
void testStrings( void ) {
    int num_configs = 5; 
    XPPCItem *configs = XPPCInit( num_configs );

    /* set defaults */
    string one   = "foo",
           two   = "bar",
           three = "baz",
           four  = "fizz",
           five  = "buzz";
/*
string
Hello World!

string2
!dlroW olleH

string 3
cats

string 4
dogs

string 5
potatoes
*/

    /* defaults */
    configs[0].type = XPPC_TYPE_STRING;
    configs[0].key  = "string";
    configs[0].ref  = &one;

    /* min = strlen */
    configs[1].type = XPPC_TYPE_STRING;
    configs[1].key  = "string2";
    configs[1].ref  = &two;
    configs[1].min  = 9;

    /* min > strlen */
    configs[2].type = XPPC_TYPE_STRING;
    configs[2].key  = "string 3";
    configs[2].ref  = &three;
    configs[2].min  = 5;

    /* max = strlen */
    configs[3].type = XPPC_TYPE_STRING;
    configs[3].key  = "string 4";
    configs[3].ref  = &four;
    configs[3].max  = 4;

    /* max < strlen */
    configs[4].type = XPPC_TYPE_STRING;
    configs[4].key  = "string 5";
    configs[4].ref  = &five;
    configs[4].max  = 7;
    
    XPPCParseConfigFile( "./test_conf.txt", configs, num_configs );

    printf( "\ntesting strings....\n" );
    assertString( one, "Hello World!" );
    assertString( two, "!dlroW olleH" );
    assertString( three, "baz" );
    assertString( four, "dogs" );
    assertString( five, "buzz" );
}