156main(
int argc,
const char * argv[])
158 appTitle =
"OKS data files comparer. OKS kernel version ";
161 bool printAttributeDifferences =
false;
162 bool printRelationshipDifferences =
false;
163 bool printCompositeParentsMode =
false;
164 bool verboseMode =
false;
166 const char * appName =
"oks_diff_data";
176 const char ** schemaFiles =
new const char * [argc];
179 const char * dataFile1 = 0;
180 const char * dataFile2 = 0;
182 const char * class_name = 0;
183 const char * object_id = 0;
185 for(
int i = 1; i < argc; i++) {
186 if(!strcmp(argv[i],
"-a") || !strcmp(argv[i],
"--attributes"))
187 printAttributeDifferences =
true;
188 else if(!strcmp(argv[i],
"-r") || !strcmp(argv[i],
"--relationships"))
189 printRelationshipDifferences =
true;
190 else if(!strcmp(argv[i],
"-p") || !strcmp(argv[i],
"--composite-parents"))
191 printCompositeParentsMode =
true;
192 else if(!strcmp(argv[i],
"-all") || !strcmp(argv[i],
"--all")) {
193 printAttributeDifferences =
true;
194 printRelationshipDifferences =
true;
195 printCompositeParentsMode =
true;
197 else if(!strcmp(argv[i],
"-b") || !strcmp(argv[i],
"--verbose"))
199 else if(!strcmp(argv[i],
"-h")) {
203 else if(!strcmp(argv[i],
"--help")) {
207 else if(!strcmp(argv[i],
"-v") || !strcmp(argv[i],
"--version")) {
211 else if(!strcmp(argv[i],
"-s") || !strcmp(argv[i],
"--schema-files")) {
212 for(
int j = 0; j < argc - i - 1; ++j) {
213 if(argv[i+1+j][0] !=
'-') schemaFiles[j] = argv[i+1+j];
221 else if(!strcmp(argv[i],
"-c") || !strcmp(argv[i],
"--class-name")) {
222 if(argv[i+1][0] !=
'-') class_name=argv[++i];
224 else if(!strcmp(argv[i],
"-o") || !strcmp(argv[i],
"--object-id")) {
225 if(argv[i+1][0] !=
'-') object_id=argv[++i];
227 else if(!strcmp(argv[i],
"-d1") || !strcmp(argv[i],
"--data-file1")) {
228 if(argv[i+1][0] !=
'-') dataFile1=argv[++i];
230 else if(!strcmp(argv[i],
"-d2") || !strcmp(argv[i],
"--data-file2")) {
231 if(argv[i+1][0] !=
'-') dataFile2=argv[++i];
234 std::cerr <<
"ERROR: Unknown parameter: \"" << argv[i] <<
"\"\n\n";
244 std::cerr <<
"ERROR: First data file is not defined.\n\n";
250 std::cerr <<
"ERROR: Second data file is not defined.\n\n";
258 if(object_id && !class_name) {
259 std::cerr <<
"ERROR: object ID cannot be used without class name.\n\n";
265 int return_status = 0;
280 for(
int i=0; schemaFiles[i] != 0; ++i) {
281 const char *s_file = schemaFiles[i];
291 OksClass::Map::const_iterator class_iterator = classes.begin();
293 if(classes.empty()) {
294 std::cerr <<
"ERROR: No classes were found in loaded schema file(s), exiting ...\n";
298 std::cout << std::endl;
303 for(;class_iterator != classes.end(); ++class_iterator) {
304 c1 = class_iterator->second;
305 std::string className(c1->
get_name());
307 if(class_name && className != class_name) {
314 std::cout <<
"TESTING IN CLASS \"" << className <<
"\"... ";
321 " Database \'" << dataFile2 <<
"\' does not have class \"" << className <<
"\", skip testing ...\n";
328 " Class \"" << className <<
"\" is different in \"" << dataFile1 <<
"\" and \"" << dataFile2 <<
"\", skip testing ...\n";
334 OksObject::Map::const_iterator object_iterator = objects1->begin();
336 for(;object_iterator != objects1->end(); ++object_iterator) {
337 const std::string * objUID = (*object_iterator).first;
338 OksObject * o1 = (*object_iterator).second;
340 if(object_id && o1->
GetId() != object_id) {
349 " There is no object " << o1 <<
" in the \"" << dataFile2 <<
"\" database file.\n";
353 if(*o1 == *o2)
continue;
356 std::cout <<
" DIFFERENCE " << ++
classDiffsCount <<
". The OBJECTS " << o1 <<
" differed:\n";
358 int objDiffsCount = 0;
365 for(std::list<OksAttribute *>::const_iterator ai = alist->begin(); ai != alist->end(); ++ai) {
373 if(printAttributeDifferences) {
375 <<
" The ATTRIBUTE \"" << a->
get_name() <<
"\" values differed:\n"
376 " the value in the FILE \"" << dataFile1 <<
"\" is: " << *d1 <<
"\n"
377 " the value in the FILE \"" << dataFile2 <<
"\" is: " << *d2 << std::endl;
385 for(std::list<OksRelationship *>::const_iterator ri = rlist->begin(); ri != rlist->end(); ++ri) {
393 if(printRelationshipDifferences) {
395 <<
" The RELATIONSHIP \"" << r->get_name() <<
"\" values differed:\n"
396 " the value in the FILE \"" << dataFile1 <<
"\" is: " << *d1 <<
"\n"
397 " the value in the FILE \"" << dataFile2 <<
"\" is: " << *d2 << std::endl;
403 if(objDiffsCount && printCompositeParentsMode) {
404 std::cout <<
" COMPOSITE PARENT(S) of the OBJECTS " << o1 <<
":\n";
411 object_iterator = objects2->begin();
413 for(;object_iterator != objects2->end(); ++object_iterator) {
414 const std::string * objUID = (*object_iterator).first;
417 if(!o1 && (!object_id || *objUID == object_id)) {
420 " There is no object " << (*object_iterator).second <<
" in the \"" << dataFile1 <<
"\" database file.\n";
425 std::cout <<
" no differences were found\n";
431 std::cerr <<
"Caught oks exception:\n" << ex << std::endl;
435 catch (std::exception & e) {
436 std::cerr <<
"Caught standard C++ exception: " << e.what() << std::endl;
441 std::cerr <<
"Caught unknown exception" << std::endl;
445 delete [] schemaFiles;
448 std::cout <<
"\nExiting " << appName <<
"...\n";
450 return return_status;