static int test_jorm_array_manipulations(void) { struct bob **a1 = NULL, **a2 = NULL; struct bob *b, *b2, *b3; b = JORM_ARRAY_APPEND_bob(&a1); EXPECT_NOT_EQUAL(b, NULL); EXPECT_EQUAL(b->a, JORM_INVAL_INT); EXPECT_NOT_EQUAL(a1[0], NULL); JORM_ARRAY_REMOVE_bob(&a1, b); EXPECT_EQUAL(a1[0], NULL); b = JORM_ARRAY_APPEND_bob(&a2); b->a = 1; b2 = JORM_ARRAY_APPEND_bob(&a2); b2->a = 2; b3 = JORM_ARRAY_APPEND_bob(&a2); b3->a = 3; JORM_ARRAY_REMOVE_bob(&a2, b2); EXPECT_EQUAL(a2[0], b); EXPECT_EQUAL(a2[1], b3); EXPECT_EQUAL(a2[2], NULL); JORM_ARRAY_FREE_bob(&a1); JORM_ARRAY_FREE_bob(&a2); return 0; }
int main(int argc, char** argv) { struct sockaddr_in server_addr, client_addr; socklen_t client_len; int fd, conn_fd, r; char buf[4 * NBYTES], *pbuf = buf; struct iovec iov; struct msghdr msg = { NULL, 0, &iov, 1, NULL, 0, 0 }; server_addr.sin_family = AF_INET; server_addr.sin_addr.s_addr = htonl(INADDR_ANY); server_addr.sin_port = htons(1080); PRINT("Trying socket()... "); fd = socket(PF_INET, SOCK_DGRAM, 0); EXPECT_SUCCESS(fd); PRINT("Trying bind()... "); r = bind(fd, (const struct sockaddr *) &server_addr, sizeof(server_addr)); EXPECT_SUCCESS(r); PRINT("Trying recvfrom()... "); client_len = sizeof(client_addr); r = recvfrom(fd, pbuf, NBYTES, 0, (struct sockaddr *) &client_addr, &client_len); EXPECT_EQUAL(r, NBYTES); ASSUME_EQUAL_STR(pbuf, "foo"); pbuf += NBYTES; PRINT("Trying recvmsg()... "); iov.iov_base = pbuf; iov.iov_len = NBYTES; r = recvmsg(fd, &msg, 0); EXPECT_EQUAL(r, NBYTES); ASSUME_EQUAL_STR(pbuf, "bar"); pbuf += NBYTES; PRINT("Trying recv()... "); r = recv(fd, pbuf, NBYTES, 0); EXPECT_EQUAL(r, NBYTES); ASSUME_EQUAL_STR(pbuf, "baz"); pbuf += NBYTES; PRINT("Trying read()... "); r = read(fd, pbuf, NBYTES); EXPECT_EQUAL(r, NBYTES); ASSUME_EQUAL_STR(pbuf, "qux"); pbuf += NBYTES; PRINT("Trying sendto()... "); r = sendto(fd, buf, pbuf - buf, 0, (const struct sockaddr *) &client_addr, client_len); EXPECT_EQUAL(r, pbuf - buf); PRINT("Trying close()... "); r = close(fd); EXPECT_SUCCESS(r); printf("Success\n"); return EXIT_SUCCESS; }
int main(int argc, char **argv) { struct s2n_connection *conn; uint8_t mac_key[] = "sample mac key"; uint8_t aes128_key[] = "123456789012345"; struct s2n_blob aes128 = {.data = aes128_key,.size = sizeof(aes128_key) }; uint8_t random_data[S2N_LARGE_RECORD_LENGTH + 1]; struct s2n_blob r = {.data = random_data, .size = sizeof(random_data)}; BEGIN_TEST(); EXPECT_NOT_NULL(conn = s2n_connection_new(S2N_SERVER)); EXPECT_SUCCESS(s2n_get_urandom_data(&r)); /* Peer and we are in sync */ conn->server = &conn->secure; conn->client = &conn->secure; /* test the AES128 cipher with a SHA1 hash */ conn->secure.cipher_suite->cipher = &s2n_aes128; conn->secure.cipher_suite->hmac_alg = S2N_HMAC_SHA1; EXPECT_SUCCESS(conn->secure.cipher_suite->cipher->get_encryption_key(&conn->secure.server_key, &aes128)); EXPECT_SUCCESS(conn->secure.cipher_suite->cipher->get_decryption_key(&conn->secure.client_key, &aes128)); EXPECT_SUCCESS(s2n_hmac_init(&conn->secure.client_record_mac, S2N_HMAC_SHA1, mac_key, sizeof(mac_key))); EXPECT_SUCCESS(s2n_hmac_init(&conn->secure.server_record_mac, S2N_HMAC_SHA1, mac_key, sizeof(mac_key))); conn->actual_protocol_version = S2N_TLS11; /* Align the record size, then subtract 20 bytes for the HMAC, 16 bytes for the explicit IV, and one byte * for the padding length byte. */ int small_aligned_payload = S2N_SMALL_FRAGMENT_LENGTH - (S2N_SMALL_FRAGMENT_LENGTH % 16) - 20 - 16 - 1; int large_aligned_payload = S2N_LARGE_FRAGMENT_LENGTH - (S2N_LARGE_FRAGMENT_LENGTH % 16) - 20 - 16 - 1; int bytes_written; /* Check the default: small record */ EXPECT_SUCCESS(s2n_stuffer_wipe(&conn->out)); EXPECT_SUCCESS(bytes_written = s2n_record_write(conn, TLS_APPLICATION_DATA, &r)); EXPECT_EQUAL(bytes_written, small_aligned_payload); /* Check explicitly small records */ EXPECT_SUCCESS(s2n_connection_prefer_low_latency(conn)); EXPECT_SUCCESS(s2n_stuffer_wipe(&conn->out)); EXPECT_SUCCESS(bytes_written = s2n_record_write(conn, TLS_APPLICATION_DATA, &r)); EXPECT_EQUAL(bytes_written, small_aligned_payload); /* Check explicitly large records */ EXPECT_SUCCESS(s2n_connection_prefer_throughput(conn)); EXPECT_SUCCESS(s2n_stuffer_wipe(&conn->out)); EXPECT_SUCCESS(bytes_written = s2n_record_write(conn, TLS_APPLICATION_DATA, &r)); EXPECT_EQUAL(bytes_written, large_aligned_payload); /* Clean up */ EXPECT_SUCCESS(conn->secure.cipher_suite->cipher->destroy_key(&conn->secure.server_key)); EXPECT_SUCCESS(conn->secure.cipher_suite->cipher->destroy_key(&conn->secure.client_key)); EXPECT_SUCCESS(s2n_connection_free(conn)); EXPECT_SUCCESS(s2n_hmac_init(&conn->secure.server_record_mac, S2N_HMAC_SHA1, mac_key, sizeof(mac_key))); END_TEST(); }
void StringTests::subscript() { gc<String> s = String::create("abcd"); EXPECT_EQUAL('a', (*s)[0]); EXPECT_EQUAL('b', (*s)[1]); EXPECT_EQUAL('c', (*s)[2]); EXPECT_EQUAL('d', (*s)[3]); }
void Test::requireThatGenerationCanBeIncreased() { GenerationHandler gh; EXPECT_EQUAL(0u, gh.getCurrentGeneration()); EXPECT_EQUAL(0u, gh.getFirstUsedGeneration()); gh.incGeneration(); EXPECT_EQUAL(1u, gh.getCurrentGeneration()); EXPECT_EQUAL(1u, gh.getFirstUsedGeneration()); }
void LexerTests::stringLiteral() { gc<String> code = String::create("\"st\\nr\""); gc<SourceFile> source = new SourceFile(String::create("<file>"), code); Lexer lexer(source); gc<Token> token = lexer.readToken(); EXPECT_EQUAL(TOKEN_STRING, token->type()); EXPECT_EQUAL("st\nr", *token->text()); }
void StringTests::create() { gc<String> s1 = String::create("some text"); gc<String> s2 = String::create("more"); EXPECT_EQUAL(9, s1->length()); EXPECT_EQUAL("some text", *s1); EXPECT_EQUAL(4, s2->length()); EXPECT_EQUAL("more", *s2); }
void Test::testOptionsAfterArguments() { AppOptions opts("myapp bar --foo baz"); std::string option; std::string argument; ProgramOptions options(opts.getArgCount(), opts.getArguments()); options.addOption("foo", option, "Description"); options.addArgument("arg", argument, "Description"); options.parse(); EXPECT_EQUAL("baz", option); EXPECT_EQUAL("bar", argument); }
static int test_jorm_init(void) { struct bob *b1 = JORM_INIT_bob(); EXPECT_NOT_EQUAL(b1, NULL); EXPECT_EQUAL(b1->a, JORM_INVAL_INT); EXPECT_EQUAL(b1->b, JORM_INVAL_DOUBLE); EXPECT_EQUAL(b1->c, JORM_INVAL_STR); EXPECT_EQUAL(b1->d, JORM_INVAL_NESTED); EXPECT_EQUAL(b1->e, JORM_INVAL_BOOL); JORM_FREE_bob(b1); return 0; }
void ArrayTests::lastIndexOf() { Array<char> array; array.add('a'); array.add('b'); array.add('c'); array.add('b'); array.add('e'); EXPECT_EQUAL(3, array.lastIndexOf('b')); EXPECT_EQUAL(2, array.lastIndexOf('c')); EXPECT_EQUAL(-1, array.lastIndexOf('z')); }
void Test::testAsciiVariant() { AsciiFoo foo(19); EXPECT_EQUAL("19", foo.toString()); EXPECT_EQUAL("AsciiFoo(19)", foo.toString(vespalib::AsciiPrintable::VERBOSE)); { vespalib::asciistream as; as << foo; EXPECT_EQUAL("19", as.str()); std::ostringstream ost; ost << foo; EXPECT_EQUAL("19", ost.str()); } AsciiBar bar(3); EXPECT_EQUAL("3", bar.toString()); EXPECT_EQUAL("AsciiBar() {\n" " AsciiFoo(3)\n" "}", bar.toString(vespalib::AsciiPrintable::VERBOSE)); { vespalib::asciistream as; as << bar; EXPECT_EQUAL("3", as.str()); std::ostringstream ost; ost << bar; EXPECT_EQUAL("3", ost.str()); } }
void ArrayTests::truncate() { Array<char> array; array.add('a'); array.add('b'); array.add('c'); array.add('d'); array.add('e'); EXPECT_EQUAL(5, array.count()); // Truncate to greater size does nothing. array.truncate(7); EXPECT_EQUAL(5, array.count()); // Truncate to same size does nothing. array.truncate(5); EXPECT_EQUAL(5, array.count()); array.truncate(3); EXPECT_EQUAL(3, array.count()); EXPECT_EQUAL('a', array[0]); EXPECT_EQUAL('b', array[1]); EXPECT_EQUAL('c', array[2]); array.truncate(0); EXPECT_EQUAL(0, array.count()); }
static int test3(void) { size_t i; int ret; char err[512] = { 0 }; const char in_str[] = "{ \"a\": 1, \"b\": 2.500000, " "\"c\": \"hi there\", \"d\": { \"a\": 0 }, " "\"e\": false, \"f\": [ { \"a\": 1 }, " "{ \"a\": 2 } ], \"x\" : 5, \"y\" : 1.5 }"; int expected_array_val[] = { 1, 2, 6 }; struct json_object* jo = NULL; struct bob *my_bob = NULL; struct abbie* final_abbie; jo = parse_json_string(in_str, err, sizeof(err)); if (err[0]) { fprintf(stderr, "parse_json_string error: %s\n", err); ret = EXIT_FAILURE; goto done; } my_bob = JORM_FROMJSON_bob(jo); if (!my_bob) { fprintf(stderr, "JORM_FROMJSON: OOM\n"); ret = EXIT_FAILURE; goto done; } ret = 0; EXPECT_NONZERO(my_bob->a == 1); EXPECT_NONZERO(my_bob->b == 2.5); EXPECT_ZERO(my_bob->extra_data); final_abbie = JORM_ARRAY_APPEND_abbie(&my_bob->f); EXPECT_NOT_EQUAL(final_abbie, NULL); final_abbie->a = 6; for (i = 0; i < sizeof(expected_array_val) / sizeof(expected_array_val[0]); ++i) { EXPECT_EQUAL(my_bob->f[i]->a, expected_array_val[i]); } EXPECT_EQUAL(my_bob->g->x, 5); EXPECT_EQUAL(my_bob->g->y, 1.5); done: if (jo) { json_object_put(jo); jo = NULL; } if (my_bob) { JORM_FREE_bob(my_bob); my_bob = NULL; } return ret; }
void Test::testAllHiddenOption() { AppOptions opts("myapp --foo bar"); std::string option; ProgramOptions options(opts.getArgCount(), opts.getArguments()); options.addOption("", option, "Description"); options.addHiddenIdentifiers("foo"); std::ostringstream actual; options.writeSyntaxPage(actual); std::string expected("\nUsage: myapp\n"); EXPECT_EQUAL(expected, actual.str()); options.parse(); EXPECT_EQUAL("bar", option); }
int main(int argc, char **argv) { struct s2n_stuffer dhparams_in, dhparams_out; struct s2n_dh_params dh_params; struct s2n_blob b; BEGIN_TEST(); EXPECT_EQUAL(s2n_get_private_random_bytes_used(), 0); /* Parse the DH params */ b.data = dhparams; b.size = sizeof(dhparams); EXPECT_SUCCESS(s2n_stuffer_alloc(&dhparams_in, sizeof(dhparams))); EXPECT_SUCCESS(s2n_stuffer_alloc(&dhparams_out, sizeof(dhparams))); EXPECT_SUCCESS(s2n_stuffer_write(&dhparams_in, &b)); EXPECT_SUCCESS(s2n_stuffer_dhparams_from_pem(&dhparams_in, &dhparams_out)); b.size = s2n_stuffer_data_available(&dhparams_out); b.data = s2n_stuffer_raw_read(&dhparams_out, b.size); EXPECT_SUCCESS(s2n_pkcs3_to_dh_params(&dh_params, &b)); EXPECT_SUCCESS(s2n_dh_generate_ephemeral_key(&dh_params)); /* Verify that our DRBG is called and that over-riding works */ EXPECT_NOT_EQUAL(s2n_get_private_random_bytes_used(), 0); EXPECT_SUCCESS(s2n_dh_params_free(&dh_params)); EXPECT_SUCCESS(s2n_stuffer_free(&dhparams_out)); EXPECT_SUCCESS(s2n_stuffer_free(&dhparams_in)); END_TEST(); }
void Test::testSyntaxPage() { AppOptions opts("myapp"); MyOptions options(opts.getArgCount(), opts.getArguments()); std::ostringstream actual; options.writeSyntaxPage(actual); std::string expected( "\nA test program to see if this utility works.\n\n" "Usage: myapp [options] <argString> <argInt> [argOptionalString] [argSecondOptional]\n\n" "Arguments:\n" " argString (string) : Required string argument.\n" " argInt (int) : Required int argument.\n" " argOptionalString (string)\n" " : Optional string argument with a long description so\n" " we can see that it will be broken correctly.\n" " (optional)\n" " argSecondOptional (int) : Yet another optional argument (optional)\n\n" "Options:\n" " --uintopt -u <uint> : Sets an unsigned int (required)\n" " -b --bool : Enables a flag\n" " --boolwithdef : If set turns to false\n" " --intopt -i <int> : Sets a signed int (default 5)\n" " --floatopt <float> : Sets a float\n" " Multiline baby (default 4)\n" " --string -s <string> : Sets a string value. This is a very long description\n" " that should be broken down into multiple lines in some\n" " sensible way. (default \"ballalaika\")\n\n" "Advanced options:\n" " -p --properties <key> <value> : Property map (default empty)\n" ); EXPECT_EQUAL(expected, actual.str()); }
void Test::requireThatGenerationCanGrowLarge() { GenerationHandler gh; std::deque<GenGuard> guards; for (size_t i = 0; i < 10000; ++i) { EXPECT_EQUAL(i, gh.getCurrentGeneration()); guards.push_back(gh.takeGuard()); // take guard on current generation if (i >= 128) { EXPECT_EQUAL(i - 128, gh.getFirstUsedGeneration()); guards.pop_front(); EXPECT_EQUAL(128u, gh.getGenerationRefCount()); } gh.incGeneration(); } }
void ArrayTests::create() { { Array<int> array; EXPECT_EQUAL(0, array.count()); EXPECT_EQUAL(0, array.capacity()); } { Array<int> array(5); EXPECT_EQUAL(0, array.count()); EXPECT(array.capacity() >= 5); } }
// TODO: hacky, parses arbitrary code string into a module void ParserTests::testCode(const char* sourceString, const char* expected) { gc<String> code = String::create(sourceString); ErrorReporter reporter; gc<SourceFile> source = new SourceFile(String::create("<file>"), code); Parser parser(source, reporter); gc<ModuleAst> module = parser.parseModule(); int numErrors = reporter.numErrors(); EXPECT_EQUAL(0, numErrors); if (numErrors == 0) { gc<String> text = module->body()->toString(); EXPECT_EQUAL(expected, *text); } }
bool Messages60Test::testStatBucketMessage() { StatBucketMessage msg(document::BucketId(16, 123), "id.user=123"); msg.setBucketSpace("andrei"); EXPECT_EQUAL(MESSAGE_BASE_LENGTH + 27u + serializedLength("andrei"), serialize("StatBucketMessage", msg)); for (uint32_t lang = 0; lang < NUM_LANGUAGES; ++lang) { mbus::Routable::UP obj = deserialize("StatBucketMessage", DocumentProtocol::MESSAGE_STATBUCKET, lang); if (EXPECT_TRUE(obj.get() != NULL)) { StatBucketMessage &ref = static_cast<StatBucketMessage&>(*obj); EXPECT_EQUAL(document::BucketId(16, 123), ref.getBucketId()); EXPECT_EQUAL("id.user=123", ref.getDocumentSelection()); EXPECT_EQUAL("andrei", ref.getBucketSpace()); } } return true; }
void StringTests::concat() { gc<String> s1 = String::create("first"); gc<String> s2 = String::create("second"); gc<String> result = String::concat(s1, s2); EXPECT_EQUAL("firstsecond", *result); }
bool Messages60Test::testGetBucketListMessage() { GetBucketListMessage msg(document::BucketId(16, 123)); msg.setLoadType(_loadTypes["foo"]); msg.setBucketSpace("beartato"); EXPECT_EQUAL(string("foo"), msg.getLoadType().getName()); EXPECT_EQUAL(MESSAGE_BASE_LENGTH + 12u + serializedLength("beartato"), serialize("GetBucketListMessage", msg)); for (uint32_t lang = 0; lang < NUM_LANGUAGES; ++lang) { mbus::Routable::UP obj = deserialize("GetBucketListMessage", DocumentProtocol::MESSAGE_GETBUCKETLIST, lang); if (EXPECT_TRUE(obj.get() != NULL)) { GetBucketListMessage &ref = static_cast<GetBucketListMessage&>(*obj); EXPECT_EQUAL(string("foo"), ref.getLoadType().getName()); EXPECT_EQUAL(document::BucketId(16, 123), ref.getBucketId()); EXPECT_EQUAL("beartato", ref.getBucketSpace()); } } return true; }
int main(int argc, char **argv) { BEGIN_TEST(); /* Test generate->write->read->compute_shared with all supported curves */ for (int i = 0; i < sizeof(s2n_ecc_supported_curves) / sizeof(s2n_ecc_supported_curves[0]); i++) { struct s2n_ecc_params server_params, client_params; struct s2n_stuffer wire; struct s2n_blob server_shared, client_shared, ecdh_params_sent, ecdh_params_received; EXPECT_SUCCESS(s2n_stuffer_growable_alloc(&wire, 1024)); /* Server generates a key for a given curve */ server_params.negotiated_curve = &s2n_ecc_supported_curves[i]; EXPECT_SUCCESS(s2n_ecc_generate_ephemeral_key(&server_params)); /* Server sends the public */ EXPECT_SUCCESS(s2n_ecc_write_ecc_params(&server_params, &wire, &ecdh_params_sent)); /* Client reads the public */ struct s2n_ecdhe_raw_server_params ecdhe_data = {{0}}; EXPECT_SUCCESS(s2n_ecc_read_ecc_params(&wire, &ecdh_params_received, &ecdhe_data)); EXPECT_SUCCESS(s2n_ecc_parse_ecc_params(&client_params, &ecdhe_data)); /* The client got the curve */ EXPECT_EQUAL(client_params.negotiated_curve, server_params.negotiated_curve); /* Client sends its public */ EXPECT_SUCCESS(s2n_ecc_compute_shared_secret_as_client(&client_params, &wire, &client_shared)); /* Server receives it */ EXPECT_SUCCESS(s2n_ecc_compute_shared_secret_as_server(&server_params, &wire, &server_shared)); /* Shared is the same for the client and the server */ EXPECT_EQUAL(client_shared.size, server_shared.size); EXPECT_BYTEARRAY_EQUAL(client_shared.data, server_shared.data, client_shared.size); /* Clean up */ EXPECT_SUCCESS(s2n_stuffer_free(&wire)); EXPECT_SUCCESS(s2n_free(&server_shared)); EXPECT_SUCCESS(s2n_free(&client_shared)); EXPECT_SUCCESS(s2n_ecc_params_free(&server_params)); EXPECT_SUCCESS(s2n_ecc_params_free(&client_params)); } END_TEST(); }
int test_str_to_int(void) { int i; char err[512] = { 0 }; err[0] = '\0'; str_to_int("123", 10, &i, err, sizeof(err)); EXPECT_ZERO(err[0]); EXPECT_EQUAL(i, 123); err[0] = '\0'; str_to_int("0", 10, &i, err, sizeof(err)); EXPECT_ZERO(err[0]); EXPECT_EQUAL(i, 0); err[0] = '\0'; str_to_int("", 10, &i, err, sizeof(err)); EXPECT_NONZERO(err[0]); err[0] = '\0'; str_to_int("10b", 10, &i, err, sizeof(err)); EXPECT_NONZERO(err[0]); err[0] = '\0'; str_to_int("f", 16, &i, err, sizeof(err)); EXPECT_ZERO(err[0]); EXPECT_EQUAL(i, 15); err[0] = '\0'; str_to_int("8589934592", 10, &i, err, sizeof(err)); EXPECT_NONZERO(err[0]); err[0] = '\0'; str_to_int("2147483647", 10, &i, err, sizeof(err)); EXPECT_ZERO(err[0]); EXPECT_EQUAL(i, 2147483647); err[0] = '\0'; str_to_int("blah", 10, &i, err, sizeof(err)); EXPECT_NONZERO(err[0]); return 0; }
void StringTests::substring() { gc<String> s = String::create("abcdef"); // Zero-length. gc<String> sub = s->substring(3, 3); EXPECT_EQUAL("", *sub); // From beginning. sub = s->substring(0, 2); EXPECT_EQUAL("ab", *sub); // In middle. sub = s->substring(2, 5); EXPECT_EQUAL("cde", *sub); // To end. sub = s->substring(4, 6); EXPECT_EQUAL("ef", *sub); }
void Test::testVectorArgument() { AppOptions opts("myapp foo bar baz"); std::vector<std::string> args; ProgramOptions options(opts.getArgCount(), opts.getArguments()); options.addListArgument("ids", args, "Vector element"); std::ostringstream actual; options.writeSyntaxPage(actual); std::string expected( "\nUsage: myapp [ids...]\n\n" "Arguments:\n" " ids (string[]) : Vector element\n" ); EXPECT_EQUAL(expected, actual.str()); options.parse(); EXPECT_EQUAL(3u, args.size()); EXPECT_EQUAL("foo", args[0]); EXPECT_EQUAL("bar", args[1]); EXPECT_EQUAL("baz", args[2]); }
void MemoryTests::collect() { Memory::shutDown(); ConsRoots roots; Memory::initialize(&roots, sizeof(Cons) * 400); EXPECT_EQUAL(0, Memory::numCollections()); gc<Cons> notRoot; // Make two long cons chains, only one of which is rooted. gc<Cons>* a = &roots.root; gc<Cons>* b = ¬Root; int id = 0; for (int i = 0; i <= 600; i++) { a->set(new Cons(id)); a = &((*a)->next); b->set(new Cons(id)); b = &((*b)->next); id++; } // Make sure the rooted ones are still valid. int last = -1; gc<Cons> c = roots.root; while (!c.isNull()) { EXPECT_EQUAL(last + 1, c->id); last = c->id; c = c->next; } // Make sure it actually did a collection. EXPECT(Memory::numCollections() > 0); }
static int test_copy_fd_to_fd(const char *tempdir, int *next_id, const char *buf) { size_t buf_len = strlen(buf); ssize_t res; char *nbuf, src_file[PATH_MAX], dst_file[PATH_MAX]; FILE *ifp, *ofp; int ret; EXPECT_ZERO(zsnprintf(src_file, sizeof(src_file), "%s/src_file.%d", tempdir, *next_id)); EXPECT_ZERO(zsnprintf(dst_file, sizeof(dst_file), "%s/dst_file.%d", tempdir, *next_id)); *next_id = *next_id + 1; ifp = fopen(src_file, "w"); if (!ifp) { ret = errno; return ret; } EXPECT_EQUAL(fwrite(buf, 1, buf_len, ifp), buf_len); ifp = freopen(src_file, "r", ifp); if (!ifp) { ret = errno; return ret; } ofp = fopen(dst_file, "w"); if (!ofp) { ret = errno; fclose(ifp); return ret; } ret = copy_fd_to_fd(fileno(ifp), fileno(ofp)); EXPECT_ZERO(ret); fclose(ofp); fclose(ifp); nbuf = calloc(1, buf_len + 1); EXPECT_NOT_EQUAL(nbuf, NULL); res = simple_io_read_whole_file_zt(dst_file, nbuf, buf_len + 1); if (res < 0) { free(nbuf); return res; } if ((res > 0) && (memcmp(buf, nbuf, buf_len - 1))) { free(nbuf); return -EIO; } free(nbuf); return 0; }
void MemoryTests::inScopeTempsArePreserved() { Memory::shutDown(); ConsRoots roots; Memory::initialize(&roots, 1024 * 1024); AllocScope scope; temp<Cons> a = Memory::makeTemp(new Cons(123)); // Force a collection. Memory::collect(); EXPECT_EQUAL(123, a->id); }
void Test::testSimple() { Foo foo(3, "myval"); Bar bar(7, 3, "otherval"); EXPECT_EQUAL("Foo(val = 3, other size 5)", foo.toString()); EXPECT_EQUAL("Foo(val = 3, other size 5)", foo.toString(false, " ")); EXPECT_EQUAL("Foo(val = 3, other:\n" " myval)", foo.toString(true)); EXPECT_EQUAL("Foo(val = 3, other:\n" " myval)", foo.toString(true, " ")); std::ostringstream ost; ost << foo; EXPECT_EQUAL("Foo(val = 3, other size 5)", ost.str()); EXPECT_EQUAL("Bar(7)", bar.toString()); EXPECT_EQUAL("Bar(7)", bar.toString(false, " ")); EXPECT_EQUAL("Bar(7) : Foo(val = 3, other:\n" " otherval)", bar.toString(true)); EXPECT_EQUAL("Bar(7) : Foo(val = 3, other:\n" " otherval)", bar.toString(true, " ")); }