8
0
mirror of https://github.com/FirebirdSQL/firebird.git synced 2025-01-23 21:23:03 +01:00
This commit is contained in:
robocop 2009-01-15 11:04:40 +00:00
parent e2359b7905
commit 94b0541550

View File

@ -50,7 +50,8 @@ typedef string AbstractString;
#include <time.h> #include <time.h>
#ifdef DEV_BUILD #ifdef DEV_BUILD
void CheckStr(const AbstractString& check, const char* want, int line) { void CheckStr(const AbstractString& check, const char* want, int line)
{
if (strlen(check.c_str()) != check.length()) { if (strlen(check.c_str()) != check.length()) {
printf("Length error at %d\n\n", line); printf("Length error at %d\n\n", line);
} }
@ -64,8 +65,9 @@ void CheckStr(const AbstractString& check, const char* want, int line) {
#define check(a, b) #define check(a, b)
#endif #endif
void test(void) { void test()
{ {
{
string a; string a;
validate(a, ""); validate(a, "");
a = lbl; a = lbl;
@ -83,8 +85,9 @@ void test(void) {
#endif #endif
string j(&lbl[3], &lbl[5]); string j(&lbl[3], &lbl[5]);
validate(j, "34"); validate(j, "34");
} }
{
{
string a = lbl; string a = lbl;
string b; string b;
b = a; b = a;
@ -107,44 +110,51 @@ void test(void) {
*z = 0; *z = 0;
b = y; b = y;
validate(b, lbl); validate(b, lbl);
} }
#ifdef FULL_FIRE #ifdef FULL_FIRE
{ {
const string a = lbl; const string a = lbl;
string b = a.at(5); string b = a.at(5);
validate(b, "5"); validate(b, "5");
} }
{
{
string a = lbl; string a = lbl;
string b = a.at(5); string b = a.at(5);
validate(b, "5"); validate(b, "5");
} }
#endif #endif
// conflict with J. requirement to string class - operator const char* {
// string a = lbl; // conflict with J. requirement to string class - operator const char*
// char c = a[5]; // {
// a[5] = 'u'; // string a = lbl;
// validate(a, "01234u6789"); // char c = a[5];
//} // a[5] = 'u';
{ // validate(a, "01234u6789");
// }
{
string a = lbl; string a = lbl;
char c = a[5]; // via operator const char* char c = a[5]; // via operator const char*
a.at(5) = 'u'; a.at(5) = 'u';
a.at(7) = c; a.at(7) = c;
validate(a, "01234u6589"); validate(a, "01234u6589");
} }
#ifdef CHECK_FATAL_RANGE_EXCEPTION #ifdef CHECK_FATAL_RANGE_EXCEPTION
{ {
const string a = lbl; const string a = lbl;
string b = a.at(15); string b = a.at(15);
} }
#endif #endif
{
{
string a = lbl; string a = lbl;
a.resize(15, 'u'); a.resize(15, 'u');
validate(a, "0123456789uuuuu"); validate(a, "0123456789uuuuu");
} }
{
{
string a; string a;
string x = lbl; string x = lbl;
x += lbl; x += lbl;
@ -167,8 +177,9 @@ void test(void) {
x += lbl; //40 bytes x += lbl; //40 bytes
a = x; a = x;
validate(a, x.c_str()); validate(a, x.c_str());
} }
{
{
string a = lbl; string a = lbl;
const string b = a; const string b = a;
a += b; a += b;
@ -181,8 +192,9 @@ void test(void) {
a = lbl; a = lbl;
a += 'u'; a += 'u';
validate(a, "0123456789u"); validate(a, "0123456789u");
} }
{
{
string a, b, c; string a, b, c;
a = "uuu"; a = "uuu";
@ -204,8 +216,9 @@ void test(void) {
validate(a, "uuu"); validate(a, "uuu");
validate(b, lbl); validate(b, lbl);
} }
{
{
string a = lbl; string a = lbl;
const string b = a; const string b = a;
a.append(b); a.append(b);
@ -250,8 +263,9 @@ void test(void) {
validate(a, "0123456789Something reaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaally long"); validate(a, "0123456789Something reaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaally long");
a = c; a = c;
validate(a, c.c_str()); validate(a, c.c_str());
} }
{
{
string a, b; string a, b;
b = lbl; b = lbl;
@ -276,8 +290,9 @@ void test(void) {
string::iterator y = b.end(); string::iterator y = b.end();
a.assign(x, y); a.assign(x, y);
validate(a, lbl); validate(a, lbl);
} }
{
{
string a, b = lbl; string a, b = lbl;
a = lbl; a = lbl;
@ -348,8 +363,9 @@ void test(void) {
y -= 2; y -= 2;
a.erase(x, y); a.erase(x, y);
validate(a, "01289"); validate(a, "01289");
} }
{
{
string a; string a;
const string b = lbl; const string b = lbl;
string::iterator f0, t0; string::iterator f0, t0;
@ -410,8 +426,9 @@ void test(void) {
a = lbl; a = lbl;
a.replace(2, 1, "Something reaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaally long"); a.replace(2, 1, "Something reaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaally long");
validate(a, "01Something reaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaally long3456789"); validate(a, "01Something reaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaally long3456789");
} }
{
{
string a, b = lbl; string a, b = lbl;
char s[40]; char s[40];
memset(s, 0, 40); memset(s, 0, 40);
@ -426,18 +443,17 @@ void test(void) {
validate(a, lbl); validate(a, lbl);
#endif #endif
// a.swap(b); // a.swap(b);
// validate(b, "3456789"); // validate(b, "3456789");
// validate(a, lbl); // validate(a, lbl);
} }
#ifdef DEV_BUILD #ifdef DEV_BUILD
#undef check #undef check
#define check(a, b) if (a != b) printf("Wanted %d got %d at %d\n\n",\ #define check(a, b) if (a != b) printf("Wanted %d got %d at %d\n\n", b, a, __LINE__)
b, a, __LINE__)
#endif #endif
{ {
string a = "012345uuu345678"; string a = "012345uuu345678";
// 9 // 9
string b = "345"; string b = "345";
@ -483,8 +499,9 @@ void test(void) {
check(a.find_last_not_of(a), string::npos); check(a.find_last_not_of(a), string::npos);
check(a.find_first_not_of("u345", 8), 12); check(a.find_first_not_of("u345", 8), 12);
} }
{
{
string a = lbl; string a = lbl;
string b; string b;
@ -493,14 +510,15 @@ void test(void) {
b = a.substr(5, 20); b = a.substr(5, 20);
validate(b, "56789"); validate(b, "56789");
#ifdef FULL_FIRE #ifdef FULL_FIRE
b = a.substr(50, 20); b = a.substr(50, 20);
validate(b, ""); validate(b, "");
#endif #endif
} }
#ifdef FULL_FIRE #ifdef FULL_FIRE
{ {
string b; string b;
FILE *x = fopen("string_test.cpp", "rt"); FILE *x = fopen("string_test.cpp", "rt");
b.LoadFromFile(x); b.LoadFromFile(x);
@ -510,9 +528,10 @@ void test(void) {
b.LoadFromFile(x); b.LoadFromFile(x);
validate(b, "//#define CHECK_FATAL_RANGE_EXCEPTION"); validate(b, "//#define CHECK_FATAL_RANGE_EXCEPTION");
fclose(x); fclose(x);
} }
#endif #endif
{
{
string a = "Something moderaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaately long"; string a = "Something moderaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaately long";
string a1 = a; string a1 = a;
string b = a + a1; string b = a + a1;
@ -531,7 +550,7 @@ void test(void) {
string n = c; string n = c;
string o = c; string o = c;
string p = c; string p = c;
} }
#ifdef DEV_BUILD #ifdef DEV_BUILD
#undef check #undef check
@ -540,15 +559,15 @@ void test(void) {
#endif #endif
#ifdef FULL_FIRE #ifdef FULL_FIRE
{ {
PathName c = "Aa"; PathName c = "Aa";
PathName d = "AB"; PathName d = "AB";
check(c.compare(d), -1); check(c.compare(d), -1);
} }
#endif #endif
{ {
string a = lbl; string a = lbl;
string b = a; string b = a;
string c = "Aaa"; string c = "Aaa";
@ -566,9 +585,10 @@ void test(void) {
check(a.compare(1, 10, b, 1, 10), 0); check(a.compare(1, 10, b, 1, 10), 0);
check(a.compare(lbl), 0); check(a.compare(lbl), 0);
check(a.compare(1, 3, lbl + 1, 3), 0); check(a.compare(1, 3, lbl + 1, 3), 0);
} }
#ifdef FULL_FIRE #ifdef FULL_FIRE
{ {
string a = " 011100 ", b; string a = " 011100 ", b;
b = a; b = a;
@ -592,16 +612,18 @@ void test(void) {
validate(b, " 011100 "); validate(b, " 011100 ");
validate(a, " 011100 "); validate(a, " 011100 ");
} }
{
{
string a = lbl; string a = lbl;
a += '\377'; a += '\377';
string b = a; string b = a;
a += " "; a += " ";
a.rtrim(); a.rtrim();
validate(a, b.c_str()); validate(a, b.c_str());
} }
{
{
string a = "AaBbCc", b; string a = "AaBbCc", b;
b = a; b = a;
@ -613,13 +635,14 @@ void test(void) {
validate(b, "AABBCC"); validate(b, "AABBCC");
validate(a, "AaBbCc"); validate(a, "AaBbCc");
} }
#endif #endif
} }
clock_t t; clock_t t;
void start() { void start()
{
t = clock(); t = clock();
} }
@ -629,13 +652,15 @@ void start() {
#define TEST_ITEMS 100000 #define TEST_ITEMS 100000
#endif #endif
void report() { void report()
{
clock_t d = clock(); clock_t d = clock();
printf("Test of %d iterations with %s took %d milliseconds.\n", printf("Test of %d iterations with %s took %d milliseconds.\n",
TEST_ITEMS, NAME, (int)(d-t)*1000/CLOCKS_PER_SEC); TEST_ITEMS, NAME, (int) (d - t) * 1000 / CLOCKS_PER_SEC);
} }
int main(int ac, char **av) { int main(int ac, char **av)
{
int n = TEST_ITEMS; int n = TEST_ITEMS;
start(); start();
while (n--) { while (n--) {
@ -645,7 +670,7 @@ int main(int ac, char **av) {
#if defined(DEV_BUILD) && defined(FIRESTR) #if defined(DEV_BUILD) && defined(FIRESTR)
getDefaultMemoryPool()->print_contents(stdout, false); getDefaultMemoryPool()->print_contents(stdout, false);
#endif #endif
printf("Press enter to continue\n"); printf("Press enter to continue\n");
getchar(); getchar();
return 0; return 0;
} }