Test::Result test_data_src_sink() { Test::Result result("DataSink"); #if defined(BOTAN_HAS_CODEC_FILTERS) std::ostringstream oss; Botan::Pipe pipe(new Botan::Hex_Decoder, new Botan::DataSink_Stream(oss)); Botan::DataSource_Memory input_mem("65666768"); pipe.process_msg(input_mem); result.test_eq("output string", oss.str(), "efgh"); Botan::DataSource_Memory input_mem2("41414141"); pipe.process_msg(input_mem2); result.test_eq("output string", oss.str(), "efghAAAA"); std::istringstream iss("4343"); Botan::DataSource_Stream input_strm(iss); pipe.process_msg(input_strm); result.test_eq("output string", oss.str(), "efghAAAACC"); #endif return result; }
Test::Result test_data_src_sink_flush() { Test::Result result("DataSinkFlush"); #if defined(BOTAN_HAS_CODEC_FILTERS) std::string tmp_name("botan_test_data_src_sink_flush.tmp"); std::ofstream outfile(tmp_name); Botan::Pipe pipe(new Botan::Hex_Decoder, new Botan::DataSink_Stream(outfile)); Botan::DataSource_Memory input_mem("65666768"); pipe.process_msg(input_mem); std::ifstream outfile_read(tmp_name); std::stringstream ss; ss << outfile_read.rdbuf(); std::string foo = ss.str(); result.test_eq("output string", ss.str(), "efgh"); std::remove(tmp_name.c_str()); #endif return result; }
static void example(void) { int i, j; /* Just a synthetic example*/ /*Allocation 18 times*/ int number_add_block = 18, I_alloc = 9, II_alloc = 8; uint32_t k = 0x100; //!!!!!! void *succes_alloc[number_add_block]; int koef_alloc[] = { /*First allocation: I_alloc = 9*/1, 2, 3, 1, 4, 8, 3, 2, 5, /*Second allocation: II_alloc = 8*/7, 4, 1, 2, 1, 1, 6, 267, /*Third allocation: III_alloc = 1*/16 }; /*Free 12 block*/ int I_free = 5, II_free = 7; int number_of_block[] = { /*First free: I_free = 5*/3, 6, 2, 4, 8, /*Second free: II_free = 7*/12, 1, 7, 14, 15, 5, 10 }; /*First allocation*/ for (i = 0; i < I_alloc; i++) { printf("==NEW BLOCK==\n"); succes_alloc[j] = memory_allocate(koef_alloc[j] * k - 8); if (succes_alloc[j] == NULL) { printf( "\nMemory allocation error on the addition %d size of block: %d\n", j, koef_alloc[j] * k); } else { printf("block num = %d address = 0x%X\n\n", j, (uint32_t) succes_alloc[j]); } j++; } /*First memory free*/ for (i = 0; i < I_free; i++) { memory_free(succes_alloc[number_of_block[i] - 1]); printf("free block num = %d address = 0x%X\n\n", i, (uint32_t) succes_alloc[i]); } /*Second allocation*/ for (i = 0; i < II_alloc; i++) { printf("==NEW BLOCK==\n"); if (j == 13) { succes_alloc[j] = memory_allocate(koef_alloc[j] * k - 8 - 8); } else { if (j == 14) { succes_alloc[j] = memory_allocate(koef_alloc[j] * k - 8 - 3); } else { succes_alloc[j] = memory_allocate(koef_alloc[j] * k - 8); } } if (succes_alloc[j] == NULL) { printf( "\nMemory allocation error on the addition %d size of block: %d\n", j, koef_alloc[j] * k); } else { printf("block num = %d address = 0x%X\n\n", j, (uint32_t) succes_alloc[j]); } j++; } /*Second memory free*/ for (i = I_free; i < I_free + II_free; i++) { memory_free(succes_alloc[number_of_block[i] - 1]); printf("free block num = %d address = 0x%X\n\n", i, (uint32_t) succes_alloc[i]); } /*Third allocation*/ printf("==NEW BLOCK==\n"); succes_alloc[j] = memory_allocate(koef_alloc[j] * k - 8); if (succes_alloc[j] == NULL) { printf( "\nMemory allocation error on the addition %d size of block: %d\n", j, koef_alloc[j] * k); } else { printf("block num = %d address = 0x%X\n\n", j, (uint32_t) succes_alloc[j]); } printf("----------------------------------------- \n"); /*Check a result*/ input_mem(); }