📄 nodediagnose.h
字号:
// create objects for reading in // Node<Char> read_char_node_text; Node<Char> read_char_node_bin; Node<String> read_str_node_text; Node<String> read_str_node_bin; // create embedded nodes for reading // Node<Node<Char > > read_char_nn_text; Node<Node<Char > > read_char_nn_bin; Node<Node<String > > read_str_nn_text; Node<Node<String > > read_str_nn_bin; Node<Node<Node<Char > > > read_char_nnn_text; Node<Node<Node<Char > > > read_char_nnn_bin; Node<Node<Node<String > > > read_str_nnn_text; Node<Node<Node<String > > > read_str_nnn_bin; // read in the nodes and test for equivalence // if (!read_char_node_text.read(text_file, (long)0) || (read_char_node_text.ne(write_char_node))) { return Error::handle(name(), L"read", Error::TEST, __FILE__, __LINE__); } if (!read_char_node_bin.read(bin_file, (long)0) || (read_char_node_bin.ne(write_char_node))) { return Error::handle(name(), L"write", Error::TEST, __FILE__, __LINE__); } if (!read_str_node_text.read(text_file, (long)0) || (read_str_node_text.ne(write_str_node))) { return Error::handle(name(), L"read", Error::TEST, __FILE__, __LINE__); } if (!read_str_node_bin.read(bin_file, (long)0) || (read_str_node_bin.ne(write_str_node))) { return Error::handle(name(), L"write", Error::TEST, __FILE__, __LINE__); } if (!read_char_nn_text.read(text_file, (long)0) || (read_char_nn_text.ne(write_char_nn))) { return Error::handle(name(), L"read", Error::TEST, __FILE__, __LINE__); } if (!read_char_nn_bin.read(bin_file, (long)0) || (read_char_nn_bin.ne(write_char_nn))) { return Error::handle(name(), L"write", Error::TEST, __FILE__, __LINE__); } if (!read_str_nn_text.read(text_file, (long)0) || (read_str_nn_text.ne(write_str_nn))) { return Error::handle(name(), L"read", Error::TEST, __FILE__, __LINE__); } if (!read_str_nn_bin.read(bin_file, (long)0) || (read_str_nn_bin.ne(write_str_nn))) { return Error::handle(name(), L"write", Error::TEST, __FILE__, __LINE__); } if (!read_char_nnn_text.read(text_file, (long)0) || (read_char_nnn_text.ne(write_char_nnn))) { return Error::handle(name(), L"read", Error::TEST, __FILE__, __LINE__); } if (!read_char_nnn_bin.read(bin_file, (long)0) || (read_char_nnn_bin.ne(write_char_nnn))) { return Error::handle(name(), L"write", Error::TEST, __FILE__, __LINE__); } if (!read_str_nnn_text.read(text_file, (long)0) || (read_str_nnn_text.ne(write_str_nnn))) { return Error::handle(name(), L"read", Error::TEST, __FILE__, __LINE__); } if (!read_str_nnn_bin.read(bin_file, (long)0) || (read_str_nnn_bin.ne(write_str_nnn))) { return Error::handle(name(), L"write", Error::TEST, __FILE__, __LINE__); } // print the nodes out // if (level_a >= Integral::ALL) { read_char_node_text.debug(L"read_char_node_text"); read_char_node_bin.debug(L"read_char_node_bin"); read_str_node_text.debug(L"read_str_node_text"); read_str_node_bin.debug(L"read_str_node_bin"); read_char_nn_text.debug(L"read_char_nn_text"); read_char_nn_bin.debug(L"read_char_nn_bin"); read_str_nn_text.debug(L"read_str_nn_text"); read_str_nn_bin.debug(L"read_str_nn_bin"); read_char_nnn_text.debug(L"read_char_nnn_text"); read_char_nnn_bin.debug(L"read_char_nnn_bin"); read_str_nnn_text.debug(L"read_str_nnn_text"); read_str_nnn_bin.debug(L"read_str_nnn_bin"); } // close and delete the temporary files // text_file.close(); bin_file.close(); File::remove(text_filename); File::remove(bin_filename); // cleanup the memory that was created by the Node read // read_char_node_text.clear(Integral::FREE); read_char_node_bin.clear(Integral::FREE); read_str_node_text.clear(Integral::FREE); read_str_node_bin.clear(Integral::FREE); read_char_nn_text.clear(Integral::FREE); read_char_nn_bin.clear(Integral::FREE); read_str_nn_text.clear(Integral::FREE); read_str_nn_bin.clear(Integral::FREE); read_char_nnn_text.clear(Integral::FREE); read_char_nnn_bin.clear(Integral::FREE); read_str_nnn_text.clear(Integral::FREE); read_str_nnn_bin.clear(Integral::FREE); // test equality methods: // allocate nodes and Char objects to use for testing // Node<Char> char_node_0; Node<Char> char_node_1; Node<Char> char_node_2; Char character(L'a'); // initialize the characters and store them in the nodes // char_node_0.setItem(&character); // copy the node // char_node_1.assign(char_node_0); char_node_2.assign(char_node_0); // char_node_1 and char_node_2 should be the same as the char_node_0 // if (char_node_0.ne(char_node_1) || char_node_0.ne(char_node_2)) { return Error::handle(name(), L"ne", Error::TEST, __FILE__, __LINE__); } if (!char_node_0.eq(char_node_1) || !char_node_0.eq(char_node_2)) { return Error::handle(name(), L"eq", Error::TEST, __FILE__, __LINE__); } // test comparison functions for Char // Char charA(L'A'); Char charB(L'B'); char_node_0.assign(&charA); char_node_1.assign(&charB); if (!char_node_0.lt(char_node_1)) { return Error::handle(name(), L"lt", Error::TEST, __FILE__, __LINE__); } if (char_node_0.gt(char_node_1)) { return Error::handle(name(), L"gt", Error::TEST, __FILE__, __LINE__); } if (char_node_0.gt(char_node_0)) { return Error::handle(name(), L"gt", Error::TEST, __FILE__, __LINE__); } // reset indentation // if (level_a > Integral::NONE) { Console::decreaseIndention(); } //-------------------------------------------------------------------------- // // 2. class-specific public methods: // item manipulation methods // //-------------------------------------------------------------------------- // set indentation // if (level_a > Integral::NONE) { Console::put(L"testing class-specific public methods: item manipulation methods...\n"); Console::increaseIndention(); } // create a pool of objects // TObject* objects = new TObject[500]; // create an array of nodes // Node<TObject>* nodes = new Node<TObject>[1000]; // place the object in the node arrays in order // for (long i = 0; i < 500; i++) { if (!nodes[i].setItem(&objects[i])) return Error::handle(name(), L"setItem", Error::TEST, __FILE__, __LINE__); } // now create the mirror of that in the second part of the node array // for (long i = 0; i < 500; i++) { if (!nodes[i + 500].setItem(nodes[500 - i - 1].getItem())) return Error::handle(name(), L"setItem", Error::TEST, __FILE__, __LINE__); } // compare the items // for (long i = 0; i < 500; i++) { if ((nodes[i + 500].getItem())->ne(*nodes[500 - i - 1].getItem())) { return Error::handle(name(), L"getItem", Error::TEST, __FILE__, __LINE__); } } // remove all the items without storing the removed pointer // for (long i = 0; i < 1000; i++) { // remove the items // if (!nodes[i].clear()) { return Error::handle(name(), L"clear", Error::TEST, __FILE__, __LINE__); } } // now loop and make sure that all of the nodes contain NULL // for (long i = 0; i < 1000; i++) { if (nodes[i].getItem() != (TObject*)NULL) { return Error::handle(name(), L"clear", Error::TEST, __FILE__, __LINE__); } } // clean up // delete [] objects; delete [] nodes; // test the clear method // TObject obj; Node<TObject> clear_node(&obj); clear_node.clear(); if (clear_node.item_d != (TObject*)NULL) { return Error::handle(name(), L"clear", Error::TEST, __FILE__, __LINE__); } // reset indentation // if (level_a > Integral::NONE) { Console::decreaseIndention(); } //--------------------------------------------------------------------------- // // 4. print completion message // //--------------------------------------------------------------------------- // set indentation // if (level_a > Integral::NONE) { Console::put(L"testing class-specific public methods: high level item manipulation methods...\n"); Console::increaseIndention(); } // test accessByMode // Node<Char> foo; Char a(L'a'); foo.setItem(&a); Char* char_ptr; Char b; char_ptr = foo.accessByMode(&b, SYSTEM); if ((char_ptr != &b) || (char_ptr == (Char*)NULL) || (char_ptr->ne(a))) { return Error::handle(name(), L"accessByMode", Error::TEST, __FILE__, __LINE__); } char_ptr = foo.accessByMode((Char*)NULL, USER); if (char_ptr != &a) { return Error::handle(name(), L"accessByMode", Error::TEST, __FILE__, __LINE__); } // test assignByMode // foo.assignByMode(&a, SYSTEM); if ((foo.getItem() == &a) || (foo.getItem() == (Char*)NULL) || (foo.getItem()->ne(a))) { return Error::handle(name(), L"assignByMode", Error::TEST, __FILE__, __LINE__); } // normally the dstr code would do this, but for the test we have to // do it by hand // delete foo.getItem(); foo.assignByMode(&a, USER); if (foo.getItem() != &a) { return Error::handle(name(), L"assignByMode", Error::TEST, __FILE__, __LINE__); } // reset indentation // if (level_a > Integral::NONE) { Console::decreaseIndention(); } //--------------------------------------------------------------------------- // // 5. print completion message // //--------------------------------------------------------------------------- // reset indentation // if (level_a > Integral::NONE) { Console::decreaseIndention(); } if (level_a > Integral::NONE) { SysString output(L"diagnostics passed for class "); output.concat(name()); output.concat(L"\n"); Console::put(output); } // exit gracefully // return true;}// end of include file//#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -