⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 file_02.cc

📁 这是一个从音频信号里提取特征参量的程序
💻 CC
📖 第 1 页 / 共 2 页
字号:
    out.put(str1);    out.put(L"\n");  }    // close the file and reopen it to read  //  foo_wo.close();  foo_rp.open(temp_file, File::READ_PLUS, File::TEXT);  // get the string and the char  //  foo_rp.get(str2);  foo_rp.get(char2);    if (str2.ne(str1) || char2.ne(char1)) {    return Error::handle(name(), L"get", Error::TEST, __FILE__, __LINE__);  }    // close files  //  foo_rp.close();  out.close();    // binary i/o read/write have been tested in the previous session  //    // reset indentation  //  if (level_a > Integral::NONE) {    Console::decreaseIndention();  }    //---------------------------------------------------------------------------  //  // 5. class-specific public methods:  //     formatting methods  //  //---------------------------------------------------------------------------    // set indentation  //  if (level_a > Integral::NONE) {    Console::put(L"testing class-specific public methods: formatting methods...\n");    Console::increaseIndention();  }  // open a temp file  //    File screen;  if (!screen.open(temp_file, File::WRITE_ONLY , File::TEXT)) {    return Error::handle(name(), L"open", Error::TEST, __FILE__, __LINE__);  }  // set the line wrap  //  long line_wrap = 55;  screen.setLineWrap(line_wrap);    // since no indention yet, the line length should be the same as line wrap  //  long line_length = screen.getLineWrap();  if (line_length != line_wrap) {    return Error::handle(name(),L"getLineWrap",Error::TEST,__FILE__,__LINE__);  }    // output something into the file, and change its indentation  //  SysString output(L"starting output");  screen.put(output);  output.assign(L"first indent\n");  screen.put(output);    // increase the indention, now the line length should decrease the  // by the length of the indention string  //  screen.increaseIndention();   line_length -= INDENT_STR.length();    if (screen.getLineLength() != line_length) {    return Error::handle(name(), L"getLineLength", Error::TEST,			 __FILE__, __LINE__);  }    screen.put(output);  screen.put(output);  screen.put(output);  // increase the indention again  //  output.assign(L"second indent\n");  screen.put(output);    screen.increaseIndention();  line_length -= INDENT_STR.length();    if (screen.getLineLength() != line_length) {    return Error::handle(name(), L"getLineLength", Error::TEST,			 __FILE__, __LINE__);  }    // put a very long message  //  output.assign(L"this is a whole lot more text than will probably fit in the single indention, so let's just keep defining\n\n\n\n(just had four newlines) more and more text to just keep wrapping and wrapping.");  screen.put(output);  screen.put(output);  screen.put(output);  screen.put(output);    // randomly output some message into the file  //  screen.increaseIndention();  screen.increaseIndention();  output.assign(L"fo ur th in de nt ");  for (long i = 0; i < 25; i++) {    screen.put(output);  }    output.assign(L"herewehaveawordtoolongtobreak,soletsseewhatthetokenizerdoes\n\n\n\n\n");  screen.put(output);  output.assign(L"this is a whole lot more text than will probably fit in the single indention, so let's just keep defining\n(just had a newline)more and more text to just keep wrapping and wrapping.");  screen.put(output);  screen.put(output);  screen.put(output);  screen.put(output);    screen.decreaseIndention();  screen.decreaseIndention();    screen.decreaseIndention();  output.assign(L"back to first indent\n");  screen.put(output);  screen.put(output);  screen.put(output);  output.assign(L"thisisawholelotmoretextthanwillprobablyfitinthesingleindention,solet'sjustkeepdefining\n(justhadanewline)moreandmoretexttojustkeepwrappingandwrapping.");  screen.put(output);  screen.put(output);  screen.put(output);    screen.decreaseIndention();  output.assign(L"back to no indention\n");  screen.put(output);  screen.put(output);  output.assign(L"this is a whole lot more text than will probably fit in the single indention, so let's just keep defining\n(just had a newline)more and more text to just keep wrapping and wrapping.");  screen.put(output);  screen.put(output);  screen.put(output);  screen.put(output);  output.assign(L"thisisawholelotmoretextthanwillprobablyfitinthesingleindention,solet'sjustkeepdefining\n(justhadanewline)moreandmoretexttojustkeepwrappingandwrapping.");  screen.put(output);  screen.put(output);  screen.put(output);    // output debug information  //  if (level_a > Integral::BRIEF) {    screen.debug(L"file screen");  }    // close file  //  screen.close();  // reset indentation  //  if (level_a > Integral::NONE) {    Console::decreaseIndention();  }  //---------------------------------------------------------------------------  //  // 6. class-specific public methods:  //     disk file operation methods  //  //---------------------------------------------------------------------------  // set indentation  //  if (level_a > Integral::NONE) {    Console::put(L"testing class-specific public methods: disk file operation methods...\n");    Console::increaseIndention();  }    // test the system functions  //  if (level_a > Integral::BRIEF) {    Console::put(L"testing exists, rename, remove methods");  }  // make a new temp file  //  SysString new_temp;  Integral::makeTemp(new_temp);    // new_temp should not exist  //  if (exists(new_temp)) {    return  Error::handle(name(), L"exists", Error::TEST, __FILE__, __LINE__);  }  // rename the existing temp_file to new_temp  //  if (!rename(temp_file, new_temp)) {    return Error::handle(name(), L"rename", Error::TEST, __FILE__, __LINE__);  }    // new_temp should exit now, temp_file is gone  //  if (!exists(new_temp)) {    return  Error::handle(name(), L"exists", Error::TEST, __FILE__, __LINE__);  }  if (exists(temp_file)) {    return  Error::handle(name(), L"exists", Error::TEST, __FILE__, __LINE__);  }      // remove files  //  if (!remove(new_temp)) {    return Error::handle(name(), L"remove", Error::TEST, __FILE__, __LINE__);  }  if (exists(new_temp) || exists(temp_file)) {    return Error::handle(name(), L"exists", Error::TEST, __FILE__, __LINE__);  }    // test mkdir  //  if (level_a > Integral::BRIEF) {    Console::put(L"testing mkdir and rmdir methods");  }  if (!mkdir(L"/tmp/my_new_dir")) {    return Error::handle(name(), L"mkdir", Error::TEST, __FILE__, __LINE__);  }  if (!exists(L"/tmp/my_new_dir")) {    return Error::handle(name(), L"mkdir", Error::TEST, __FILE__, __LINE__);  }  if (!rmdir(L"/tmp/my_new_dir")) {    return Error::handle(name(), L"rmdir", Error::TEST, __FILE__, __LINE__);  }  if (exists(L"/tmp/my_new_dir")) {    return Error::handle(name(), L"rmdir", Error::TEST, __FILE__, __LINE__);  }  // test compare  //  if (compare(L"file_02.cc", L"file_03.cc")) {    return Error::handle(name(), L"compare", Error::TEST, __FILE__, __LINE__);  }  if (!compare(L"file_02.cc", L"file_02.cc")) {    return Error::handle(name(), L"compare", Error::TEST, __FILE__, __LINE__);  }  if (compare(L"file_02.o", L"file_06.o")) {    return Error::handle(name(), L"compare", Error::TEST, __FILE__, __LINE__);  }  if (!compare(L"file_02.o", L"file_02.o")) {    return Error::handle(name(), L"compare", Error::TEST, __FILE__, __LINE__);  }  // reset indentation  //  if (level_a > Integral::NONE) {    Console::decreaseIndention();  }    //---------------------------------------------------------------------------  //  // 7. class-specific public methods:  //     byte-order related methods  //  //---------------------------------------------------------------------------  // set indentation  //  if (level_a > Integral::NONE) {    Console::put(L"testing class-specific public methods: byte-order related methods...\n");    Console::increaseIndention();  }  // test encode method  //  File swap_file;  swap_file.setBMode(SWAP);    // test machine byte order  //  SysString machine_type;  SysString byte_order;  machine_type.assign(swap_file.getMachineByteOrder());  byte_order.assign(swap_file.getBMode());  if (level_a > Integral::BRIEF) {        // these two should one is BIG_ENDIAN, one is LITTLE_ENDIAN    //    machine_type.debug(L"machine byte order");    byte_order.debug(L"file byte order");  }  // encode int16  // a short number 1, which is 0x00 01 in hex,  // after encode, it should be 0x01 00, which is 2^8  //  int16 num_1 = 0x0001;  int16 num_2 = 0x0100;  if (swap_file.encode(num_1) != num_2) {    return Error::handle(name(), L"encode int16", Error::TEST,			 __FILE__, __LINE__);  }  // encode int32  // a short number 1, which is 0x00 01 10 11  // after encode, it should be 0x11 10 01 00  //  int32 num_3 = 0x00011011;  int32 num_4 = 0x11100100;  if (swap_file.encode(num_3) != num_4) {    return Error::handle(name(), L"encode int32", Error::TEST,			 __FILE__, __LINE__);  }   // encode int64   0x80 00 00 00 00 00 00 00  // after encode   0x00 00 00 00 00 00 00 80  //                  int64 num_5 = (int64)Integral::TWO_EXP63;  int64 num_6 = 0x0080;    if (swap_file.encode(num_5) != num_6) {    return Error::handle(name(), L"encode int64", Error::TEST,			 __FILE__, __LINE__);  }    // decode the numbers back  //  int16 num_1d = swap_file.decode(num_2);  if (num_1d != num_1) {    return Error::handle(name(), L"decode int16", Error::TEST,			 __FILE__, __LINE__);  }  int32 num_3d = swap_file.decode(num_4);  if (num_3d != num_3) {    return Error::handle(name(), L"decode int32", Error::TEST,			 __FILE__, __LINE__);  }    int64 num_5d = swap_file.decode(num_6);  if (num_5d != num_5) {    return Error::handle(name(), L"decode int64", Error::TEST,			 __FILE__, __LINE__);  }    // reset indentation  //  if (level_a > Integral::NONE) {    Console::decreaseIndention();  }    //---------------------------------------------------------------------------  //  // 8. 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;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -