31
|
1 |
|
|
2 |
// STLport regression testsuite component.
|
|
3 |
// To compile as a separate example, please #define MAIN.
|
|
4 |
|
|
5 |
#include <algorithm>
|
|
6 |
#include <iostream>
|
|
7 |
#include <iterator>
|
|
8 |
#include <fstream>
|
|
9 |
|
|
10 |
#ifdef MAIN
|
|
11 |
#define ostmit_test main
|
|
12 |
#endif
|
|
13 |
int cmp(char*,char*);
|
|
14 |
|
|
15 |
#if !defined (STLPORT) || defined(__STL_USE_NAMESPACES)
|
|
16 |
using namespace std;
|
|
17 |
#endif
|
|
18 |
int ostmit_test(int, char**)
|
|
19 |
{
|
|
20 |
cout<<"Results of ostmit_test:"<<endl;
|
|
21 |
ofstream outfile("c:\\ostmit.txt");
|
|
22 |
int array [] = { 1, 5, 2, 4 };
|
|
23 |
char* string = "hello";
|
|
24 |
ostream_iterator<char> it1(cout);
|
|
25 |
ostream_iterator<char> itfile(outfile);
|
|
26 |
copy(string, string + 5, it1);
|
|
27 |
copy(string, string + 5, itfile);
|
|
28 |
cout << endl;
|
|
29 |
outfile << endl;
|
|
30 |
|
|
31 |
ostream_iterator<int> it2(cout);
|
|
32 |
ostream_iterator<int> itfile1(outfile);
|
|
33 |
copy(array, array + 4, it2);
|
|
34 |
copy(array, array + 4, itfile1);
|
|
35 |
cout << endl;
|
|
36 |
|
|
37 |
outfile << endl;
|
|
38 |
int result = cmp("c:\\ostmit.txt","c:\\testframework\\tstdcpp\\ostmit_good.txt");
|
|
39 |
if(result)
|
|
40 |
return 0;
|
|
41 |
else
|
|
42 |
return 1;
|
|
43 |
}
|
|
44 |
|
|
45 |
|
|
46 |
int cmp(char*str1,char*str2)
|
|
47 |
{
|
|
48 |
FILE *fp1,*fp2;
|
|
49 |
char c1,c2;
|
|
50 |
int i=1,j=1;
|
|
51 |
fp1=fopen(str1,"r");
|
|
52 |
|
|
53 |
if (fp1 == NULL)
|
|
54 |
{
|
|
55 |
printf("Error 1");
|
|
56 |
return(0);
|
|
57 |
}
|
|
58 |
fp2=fopen(str2,"r");
|
|
59 |
|
|
60 |
if (fp2 == NULL)
|
|
61 |
{
|
|
62 |
printf("Error 2");
|
|
63 |
return(0);
|
|
64 |
}
|
|
65 |
c1=getc(fp1);
|
|
66 |
c2=getc(fp2);
|
|
67 |
|
|
68 |
while(!feof(fp1) && !feof(fp2))
|
|
69 |
{
|
|
70 |
// i++;
|
|
71 |
c1=getc(fp1);
|
|
72 |
c2=getc(fp2);
|
|
73 |
j++;
|
|
74 |
if(c1=='\n' && c2=='\r')
|
|
75 |
{
|
|
76 |
//for every new line there is '\r' prepended to '\n'
|
|
77 |
//so read again to get '\n'
|
|
78 |
c2=getc(fp2);
|
|
79 |
i++;
|
|
80 |
j=0;
|
|
81 |
}
|
|
82 |
|
|
83 |
|
|
84 |
if(c1!=c2)
|
|
85 |
{
|
|
86 |
printf("The Files are different\n");
|
|
87 |
printf("c1=%c c2=%c",c1,c2);
|
|
88 |
printf("i=%d",i);
|
|
89 |
|
|
90 |
return(0);
|
|
91 |
}
|
|
92 |
|
|
93 |
}
|
|
94 |
if(feof(fp1) && feof(fp2))
|
|
95 |
return 1;
|
|
96 |
else
|
|
97 |
return 0;
|
|
98 |
}
|
|
99 |
|
|
100 |
|