diff options
author | Jeff Davidson <jpd@google.com> | 2015-01-15 22:48:58 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2015-01-15 22:48:58 +0000 |
commit | 77a6b2f4cdd580d57630f079db1d908d7fd90a54 (patch) | |
tree | 586f7d5e9a7e05af45d0e821188097c0faa96219 /src/google/protobuf/io/printer_unittest.cc | |
parent | c7c25812eb19d080087b71e08bfe35aff9f21433 (diff) | |
parent | a3b2a6da25a76f17c73d31def3952feb0fd2296e (diff) | |
download | external_protobuf-77a6b2f4cdd580d57630f079db1d908d7fd90a54.zip external_protobuf-77a6b2f4cdd580d57630f079db1d908d7fd90a54.tar.gz external_protobuf-77a6b2f4cdd580d57630f079db1d908d7fd90a54.tar.bz2 |
Merge "Update protobuf library from 2.3 to 2.6."
Diffstat (limited to 'src/google/protobuf/io/printer_unittest.cc')
-rw-r--r-- | src/google/protobuf/io/printer_unittest.cc | 30 |
1 files changed, 27 insertions, 3 deletions
diff --git a/src/google/protobuf/io/printer_unittest.cc b/src/google/protobuf/io/printer_unittest.cc index 580a53d..76fb944 100644 --- a/src/google/protobuf/io/printer_unittest.cc +++ b/src/google/protobuf/io/printer_unittest.cc @@ -220,7 +220,7 @@ TEST(Printer, Indenting) { } // Death tests do not work on Windows as of yet. -#ifdef GTEST_HAS_DEATH_TEST +#ifdef PROTOBUF_HAS_DEATH_TEST TEST(Printer, Death) { char buffer[8192]; @@ -231,9 +231,33 @@ TEST(Printer, Death) { EXPECT_DEBUG_DEATH(printer.Print("$unclosed"), "Unclosed variable name"); EXPECT_DEBUG_DEATH(printer.Outdent(), "without matching Indent"); } -#endif // GTEST_HAS_DEATH_TEST +#endif // PROTOBUF_HAS_DEATH_TEST -TEST(Printer, WriteFailure) { +TEST(Printer, WriteFailurePartial) { + char buffer[17]; + + ArrayOutputStream output(buffer, sizeof(buffer)); + Printer printer(&output, '$'); + + // Print 16 bytes to almost fill the buffer (should not fail). + printer.Print("0123456789abcdef"); + EXPECT_FALSE(printer.failed()); + + // Try to print 2 chars. Only one fits. + printer.Print("<>"); + EXPECT_TRUE(printer.failed()); + + // Anything else should fail too. + printer.Print(" "); + EXPECT_TRUE(printer.failed()); + printer.Print("blah"); + EXPECT_TRUE(printer.failed()); + + // Buffer should contain the first 17 bytes written. + EXPECT_EQ("0123456789abcdef<", string(buffer, sizeof(buffer))); +} + +TEST(Printer, WriteFailureExact) { char buffer[16]; ArrayOutputStream output(buffer, sizeof(buffer)); |