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