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