149main(
int argc,
const char * argv[])
151 appTitle =
"OKS data files comparer. OKS kernel version ";
154 bool printAttributeDifferences =
false;
155 bool printRelationshipDifferences =
false;
156 bool printCompositeParentsMode =
false;
157 bool verboseMode =
false;
159 const char * appName =
"oks_diff_data";
169 const char ** schemaFiles =
new const char * [argc];
172 const char * dataFile1 = 0;
173 const char * dataFile2 = 0;
175 const char * class_name = 0;
176 const char * object_id = 0;
178 for(
int i = 1; i < argc; i++) {
179 if(!strcmp(argv[i],
"-a") || !strcmp(argv[i],
"--attributes"))
180 printAttributeDifferences =
true;
181 else if(!strcmp(argv[i],
"-r") || !strcmp(argv[i],
"--relationships"))
182 printRelationshipDifferences =
true;
183 else if(!strcmp(argv[i],
"-p") || !strcmp(argv[i],
"--composite-parents"))
184 printCompositeParentsMode =
true;
185 else if(!strcmp(argv[i],
"-all") || !strcmp(argv[i],
"--all")) {
186 printAttributeDifferences =
true;
187 printRelationshipDifferences =
true;
188 printCompositeParentsMode =
true;
190 else if(!strcmp(argv[i],
"-b") || !strcmp(argv[i],
"--verbose"))
192 else if(!strcmp(argv[i],
"-h")) {
196 else if(!strcmp(argv[i],
"--help")) {
200 else if(!strcmp(argv[i],
"-v") || !strcmp(argv[i],
"--version")) {
204 else if(!strcmp(argv[i],
"-s") || !strcmp(argv[i],
"--schema-files")) {
205 for(
int j = 0; j < argc - i - 1; ++j) {
206 if(argv[i+1+j][0] !=
'-') schemaFiles[j] = argv[i+1+j];
214 else if(!strcmp(argv[i],
"-c") || !strcmp(argv[i],
"--class-name")) {
215 if(argv[i+1][0] !=
'-') class_name=argv[++i];
217 else if(!strcmp(argv[i],
"-o") || !strcmp(argv[i],
"--object-id")) {
218 if(argv[i+1][0] !=
'-') object_id=argv[++i];
220 else if(!strcmp(argv[i],
"-d1") || !strcmp(argv[i],
"--data-file1")) {
221 if(argv[i+1][0] !=
'-') dataFile1=argv[++i];
223 else if(!strcmp(argv[i],
"-d2") || !strcmp(argv[i],
"--data-file2")) {
224 if(argv[i+1][0] !=
'-') dataFile2=argv[++i];
227 std::cerr <<
"ERROR: Unknown parameter: \"" << argv[i] <<
"\"\n\n";
237 std::cerr <<
"ERROR: First data file is not defined.\n\n";
243 std::cerr <<
"ERROR: Second data file is not defined.\n\n";
251 if(object_id && !class_name) {
252 std::cerr <<
"ERROR: object ID cannot be used without class name.\n\n";
258 int return_status = 0;
273 for(
int i=0; schemaFiles[i] != 0; ++i) {
274 const char *s_file = schemaFiles[i];
284 OksClass::Map::const_iterator class_iterator = classes.begin();
286 if(classes.empty()) {
287 std::cerr <<
"ERROR: No classes were found in loaded schema file(s), exiting ...\n";
291 std::cout << std::endl;
296 for(;class_iterator != classes.end(); ++class_iterator) {
297 c1 = class_iterator->second;
298 std::string className(c1->
get_name());
300 if(class_name && className != class_name) {
307 std::cout <<
"TESTING IN CLASS \"" << className <<
"\"... ";
314 " Database \'" << dataFile2 <<
"\' does not have class \"" << className <<
"\", skip testing ...\n";
321 " Class \"" << className <<
"\" is different in \"" << dataFile1 <<
"\" and \"" << dataFile2 <<
"\", skip testing ...\n";
327 OksObject::Map::const_iterator object_iterator = objects1->begin();
329 for(;object_iterator != objects1->end(); ++object_iterator) {
330 const std::string * objUID = (*object_iterator).first;
331 OksObject * o1 = (*object_iterator).second;
333 if(object_id && o1->
GetId() != object_id) {
342 " There is no object " << o1 <<
" in the \"" << dataFile2 <<
"\" database file.\n";
346 if(*o1 == *o2)
continue;
349 std::cout <<
" DIFFERENCE " << ++
classDiffsCount <<
". The OBJECTS " << o1 <<
" differed:\n";
351 int objDiffsCount = 0;
358 for(std::list<OksAttribute *>::const_iterator ai = alist->begin(); ai != alist->end(); ++ai) {
366 if(printAttributeDifferences) {
368 <<
" The ATTRIBUTE \"" << a->
get_name() <<
"\" values differed:\n"
369 " the value in the FILE \"" << dataFile1 <<
"\" is: " << *d1 <<
"\n"
370 " the value in the FILE \"" << dataFile2 <<
"\" is: " << *d2 << std::endl;
378 for(std::list<OksRelationship *>::const_iterator ri = rlist->begin(); ri != rlist->end(); ++ri) {
386 if(printRelationshipDifferences) {
388 <<
" The RELATIONSHIP \"" << r->get_name() <<
"\" values differed:\n"
389 " the value in the FILE \"" << dataFile1 <<
"\" is: " << *d1 <<
"\n"
390 " the value in the FILE \"" << dataFile2 <<
"\" is: " << *d2 << std::endl;
396 if(objDiffsCount && printCompositeParentsMode) {
397 std::cout <<
" COMPOSITE PARENT(S) of the OBJECTS " << o1 <<
":\n";
404 object_iterator = objects2->begin();
406 for(;object_iterator != objects2->end(); ++object_iterator) {
407 const std::string * objUID = (*object_iterator).first;
410 if(!o1 && (!object_id || *objUID == object_id)) {
413 " There is no object " << (*object_iterator).second <<
" in the \"" << dataFile1 <<
"\" database file.\n";
418 std::cout <<
" no differences were found\n";
424 std::cerr <<
"Caught oks exception:\n" << ex << std::endl;
428 catch (std::exception & e) {
429 std::cerr <<
"Caught standard C++ exception: " << e.what() << std::endl;
434 std::cerr <<
"Caught unknown exception" << std::endl;
438 delete [] schemaFiles;
441 std::cout <<
"\nExiting " << appName <<
"...\n";
443 return return_status;