00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef __loaded__data_test_cpp__
00021 #define __loaded__data_test_cpp__
00022 using namespace std;
00023 #line 1 "data-test.c++"
00024 #include "om-data.h"
00025
00026 Symbol getRandomSymbol()
00027 {
00028 int l = random()%5+3;
00029 char str[10];
00030 for(int i = 0 ; i < l ; i++)
00031 str[i]=random()%26+'a';
00032 str[l]=0;
00033 return Symbol(str);
00034 }
00035
00036 String getRandomString()
00037 {
00038 int l = random()%30;
00039 char str[100];
00040 for(int i = 0 ; i < l ; i++)
00041 str[i]=random()%26+'A';
00042 str[l]=0;
00043 return String(str);
00044 }
00045
00046 Token getRandomToken()
00047 {
00048 int l = random()%5+3;
00049 Token result;
00050 for(int i = 0 ; i < l ; i++)
00051 result[getRandomSymbol()]=getRandomString();
00052 return result;
00053 }
00054
00055 void write_and_read_test()
00056 {
00057
00058 Array<6,signed2> D6(2,2,2,2,2,2);
00059 int nr = 0;
00060 for(Array<6,signed2>::values pixel(D6); pixel.more() ; ++pixel)
00061 pixel=nr++;
00062
00063 Array<3,unsigned1> I(3,20,10);
00064 for(Array<3,unsigned1>::values pixel(I); pixel.more() ; ++pixel)
00065 pixel=nr++;
00066
00067 Array<2,Data> T(3,3);
00068 for(Array<2,Data>::values token(T) ; token.more() ; ++token)
00069 token=getRandomToken();
00070
00071 Array<1,Data> L(3);
00072 L[0]=D6;
00073 L[1]=I;
00074 L[2]=T;
00075
00076 DataTexter::write(L,stdout);
00077 DataBinner::write(L,"/tmp/test.dat");
00078 Data read = DataBinner::read("/tmp/test.dat");
00079 DataTexter::write(read,stdout);
00080 }
00081
00082 int main(int, char*[])
00083 {
00084 write_and_read_test();
00085 DataTexter texter("/tmp/dump.txt","ab");
00086
00087
00088
00089
00090 Symbol wopper("wopper");
00091
00092 Token token;
00093 Token beta;
00094 token["Alfa"] = String("Moonbase\nalfa and 'beta' djkhe "
00095 "kljsdf kzejhk \nhsdfk jhsdf kjhsdfkjhzeiury ;,hkjsdhfkjhsd "
00096 "iuyzerkjh ukhkughiuy kiu");
00097 token["Delta"] = String("Blahlbah");
00098 token["Beta"] = beta;
00099 beta.define(Symbol("wopper"),Symbol("HEY"));
00100 beta["Lange"]=Symbol("wapper");
00101 Array<1,Data> as2(2);
00102 as2[0]=Signed2(12);
00103 as2[1]=Unsigned2(19);
00104 token["Gamma"]=as2;
00105 Array<2,Data> as22(2,2);
00106 as22[XY(0,0)]=Signed8(10);
00107 as22[XY(0,1)]=Unsigned1(20);
00108 as22[XY(1,0)]=Signed2(30);
00109 as22[XY(1,1)]=Signed4(40);
00110 token["Kappa"]=as22;
00111 FILE * data = fopen("data.cpp","rb");
00112 fseek(data,0,SEEK_END);
00113 int L = ftell(data);
00114 fseek(data,0,SEEK_SET);
00115 char data_data[L];
00116 fread(data_data,L,1,data);
00117 fclose(data);
00118 data_data[L]=0;
00119 token[Symbol("data.cpp")]=String(data_data);
00120 token["ZZZZZZ"]=String("{Alfa : 'Moonbase\n"
00121 " >alfa and ''beta''\n"
00122 " | djkhe kljsdf kzejhk\n"
00123 " >hsdfk jhsdf kjhsdfk\n"
00124 " |jhzeiury ;,hkjsdhfkjh\n"
00125 " |sd iuyzerkjh ukhkughi\n"
00126 " |uy kiu';\n"
00127 " Beta : {Lange : wapper;\n"
00128 " Wopper : HEY};\n"
00129 " Delta : 'Blahlbah';\n"
00130 " Gamma : <+12w +0w +0w +0w +0w +0w +0w +0w +0w +0w +0w +0w +0w"
00131 " +0w +0w +19w>;\n"
00132 " Kappa : <<+10b +0b +0b +0b +0b +0b +0b +0b +0b +0b +20b> <> <>"
00133 " <> <> <> <> <> <> <> <+30b +0b +0b +0b +0b +0b +0b"
00134 " +0b +0b +0b\n");
00135 texter.write(token);
00136 printf("Finished\n");
00137 }
00138 #endif // __loaded__data_test_cpp__