stdcpp/tsrc/Stdcpp_test/stlport/auto/stlport_nextprm/src/nextprm1.cpp
changeset 0 e4d67989cc36
child 18 47c74d1534e1
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/stdcpp/tsrc/Stdcpp_test/stlport/auto/stlport_nextprm/src/nextprm1.cpp	Tue Feb 02 02:01:42 2010 +0200
@@ -0,0 +1,101 @@
+ 
+// STLport regression testsuite component.
+// To compile as a separate example, please #define MAIN.
+
+#include <vector>
+#include <algorithm>
+#include <numeric>
+#include <iterator>
+#include <iostream>
+#include <fstream>
+#ifdef MAIN 
+#define nextprm1_test main
+#endif
+int cmp(char*,char*);
+
+#if !defined (STLPORT) || defined(__STL_USE_NAMESPACES)
+using namespace std;
+#endif
+int nextprm1_test(int, char**)
+{
+  cout<<"Results of nextprm1_test:"<<endl;
+  ofstream outfile("c:\\nextperm1.txt");
+  vector <int> v1(3);
+  iota(v1.begin(), v1.end(), 0);
+  ostream_iterator<int> iter(cout, " ");
+  ostream_iterator<int> iterfile(outfile, " ");
+  
+  copy(v1.begin(), v1.end(), iter);
+  copy(v1.begin(), v1.end(), iterfile);
+  cout << endl;
+  outfile << endl;
+  for(int i = 0; i < 9; i++)
+  {
+    next_permutation(v1.begin(), v1.end());
+    copy(v1.begin(), v1.end(), iter);
+    copy(v1.begin(), v1.end(), iterfile); 
+    cout << endl;
+    outfile << endl;
+  }
+  outfile.close();
+  int result =  cmp("c:\\nextperm1.txt","c:\\testframework\\tstdcpp\\nextperm1_good.txt"); 
+  if(result)
+     return 0;
+  else
+  	return 1;
+}
+
+int cmp(char*str1,char*str2)
+{
+  FILE *fp1,*fp2;
+  char c1,c2;
+  int i=1,j=1;
+  fp1=fopen(str1,"r");
+ 
+  if (fp1 == NULL)
+   {
+ 	     printf("Error 1");
+       return(0);
+    }
+  fp2=fopen(str2,"r");
+  
+  if (fp2 == NULL)
+  {
+     printf("Error 2");
+     return(0);
+  }
+  c1=getc(fp1);
+  c2=getc(fp2);
+  
+ while(!feof(fp1) && !feof(fp2))
+  {
+ // i++;
+   c1=getc(fp1);
+   c2=getc(fp2);
+    j++;
+		if(c1=='\n' && c2=='\r')
+		{	
+			//for every new line there is '\r' prepended to '\n'
+			//so read again to get '\n'
+			c2=getc(fp2);
+			i++;
+			j=0;
+		}	
+
+   if(c1!=c2)
+    {
+   	   printf("The Files are different\n");
+              printf("c1=%c c2=%c",c1,c2);
+       printf("i=%d",i);
+       
+       return(0);
+     }
+
+    }
+ if(feof(fp1) && feof(fp2))  
+  	  return 1;
+ else
+   return 0;
+}
+
+