31
|
1 |
/*
|
|
2 |
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of "Eclipse Public License v1.0"
|
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description:
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
// STLport regression testsuite component.
|
|
19 |
// To compile as a separate example, please #define MAIN.
|
|
20 |
|
|
21 |
#include <vector>
|
|
22 |
#include <algorithm>
|
|
23 |
#include <numeric>
|
|
24 |
#include <iterator>
|
|
25 |
#include <iostream>
|
|
26 |
#include <fstream>
|
|
27 |
#ifdef MAIN
|
|
28 |
#define nextprm1_test main
|
|
29 |
#endif
|
|
30 |
int cmp(char*,char*);
|
|
31 |
|
|
32 |
#if !defined (STLPORT) || defined(__STL_USE_NAMESPACES)
|
|
33 |
using namespace std;
|
|
34 |
#endif
|
|
35 |
int nextprm1_test(int, char**)
|
|
36 |
{
|
|
37 |
cout<<"Results of nextprm1_test:"<<endl;
|
|
38 |
ofstream outfile("c:\\nextperm1.txt");
|
|
39 |
vector <int> v1(3);
|
|
40 |
iota(v1.begin(), v1.end(), 0);
|
|
41 |
ostream_iterator<int> iter(cout, " ");
|
|
42 |
ostream_iterator<int> iterfile(outfile, " ");
|
|
43 |
|
|
44 |
copy(v1.begin(), v1.end(), iter);
|
|
45 |
copy(v1.begin(), v1.end(), iterfile);
|
|
46 |
cout << endl;
|
|
47 |
outfile << endl;
|
|
48 |
for(int i = 0; i < 9; i++)
|
|
49 |
{
|
|
50 |
next_permutation(v1.begin(), v1.end());
|
|
51 |
copy(v1.begin(), v1.end(), iter);
|
|
52 |
copy(v1.begin(), v1.end(), iterfile);
|
|
53 |
cout << endl;
|
|
54 |
outfile << endl;
|
|
55 |
}
|
|
56 |
outfile.close();
|
|
57 |
int result = cmp("c:\\nextperm1.txt","c:\\testframework\\tstdcpp\\nextperm1_good.txt");
|
|
58 |
if(result)
|
|
59 |
return 0;
|
|
60 |
else
|
|
61 |
return 1;
|
|
62 |
}
|
|
63 |
|
|
64 |
int cmp(char*str1,char*str2)
|
|
65 |
{
|
|
66 |
FILE *fp1,*fp2;
|
|
67 |
char c1,c2;
|
|
68 |
int i=1,j=1;
|
|
69 |
fp1=fopen(str1,"r");
|
|
70 |
|
|
71 |
if (fp1 == NULL)
|
|
72 |
{
|
|
73 |
printf("Error 1");
|
|
74 |
return(0);
|
|
75 |
}
|
|
76 |
fp2=fopen(str2,"r");
|
|
77 |
|
|
78 |
if (fp2 == NULL)
|
|
79 |
{
|
|
80 |
printf("Error 2");
|
|
81 |
return(0);
|
|
82 |
}
|
|
83 |
c1=getc(fp1);
|
|
84 |
c2=getc(fp2);
|
|
85 |
|
|
86 |
while(!feof(fp1) && !feof(fp2))
|
|
87 |
{
|
|
88 |
// i++;
|
|
89 |
c1=getc(fp1);
|
|
90 |
c2=getc(fp2);
|
|
91 |
j++;
|
|
92 |
if(c1=='\n' && c2=='\r')
|
|
93 |
{
|
|
94 |
//for every new line there is '\r' prepended to '\n'
|
|
95 |
//so read again to get '\n'
|
|
96 |
c2=getc(fp2);
|
|
97 |
i++;
|
|
98 |
j=0;
|
|
99 |
}
|
|
100 |
|
|
101 |
if(c1!=c2)
|
|
102 |
{
|
|
103 |
printf("The Files are different\n");
|
|
104 |
printf("c1=%c c2=%c",c1,c2);
|
|
105 |
printf("i=%d",i);
|
|
106 |
|
|
107 |
return(0);
|
|
108 |
}
|
|
109 |
|
|
110 |
}
|
|
111 |
if(feof(fp1) && feof(fp2))
|
|
112 |
return 1;
|
|
113 |
else
|
|
114 |
return 0;
|
|
115 |
}
|
|
116 |
|
|
117 |
|