| OLD | NEW |
| 1 // Protocol Buffers - Google's data interchange format | 1 // Protocol Buffers - Google's data interchange format |
| 2 // Copyright 2008 Google Inc. All rights reserved. | 2 // Copyright 2008 Google Inc. All rights reserved. |
| 3 // http://code.google.com/p/protobuf/ | 3 // https://developers.google.com/protocol-buffers/ |
| 4 // | 4 // |
| 5 // Redistribution and use in source and binary forms, with or without | 5 // Redistribution and use in source and binary forms, with or without |
| 6 // modification, are permitted provided that the following conditions are | 6 // modification, are permitted provided that the following conditions are |
| 7 // met: | 7 // met: |
| 8 // | 8 // |
| 9 // * Redistributions of source code must retain the above copyright | 9 // * Redistributions of source code must retain the above copyright |
| 10 // notice, this list of conditions and the following disclaimer. | 10 // notice, this list of conditions and the following disclaimer. |
| 11 // * Redistributions in binary form must reproduce the above | 11 // * Redistributions in binary form must reproduce the above |
| 12 // copyright notice, this list of conditions and the following disclaimer | 12 // copyright notice, this list of conditions and the following disclaimer |
| 13 // in the documentation and/or other materials provided with the | 13 // in the documentation and/or other materials provided with the |
| (...skipping 16 matching lines...) Expand all Loading... |
| 30 | 30 |
| 31 // Author: kenton@google.com (Kenton Varda) | 31 // Author: kenton@google.com (Kenton Varda) |
| 32 // Based on original Protocol Buffers design by | 32 // Based on original Protocol Buffers design by |
| 33 // Sanjay Ghemawat, Jeff Dean, and others. | 33 // Sanjay Ghemawat, Jeff Dean, and others. |
| 34 | 34 |
| 35 #include <vector> | 35 #include <vector> |
| 36 | 36 |
| 37 #include <google/protobuf/io/printer.h> | 37 #include <google/protobuf/io/printer.h> |
| 38 #include <google/protobuf/io/zero_copy_stream_impl.h> | 38 #include <google/protobuf/io/zero_copy_stream_impl.h> |
| 39 | 39 |
| 40 #include <google/protobuf/stubs/logging.h> |
| 40 #include <google/protobuf/stubs/common.h> | 41 #include <google/protobuf/stubs/common.h> |
| 41 #include <google/protobuf/testing/googletest.h> | 42 #include <google/protobuf/testing/googletest.h> |
| 42 #include <gtest/gtest.h> | 43 #include <gtest/gtest.h> |
| 43 | 44 |
| 44 namespace google { | 45 namespace google { |
| 45 namespace protobuf { | 46 namespace protobuf { |
| 46 namespace io { | 47 namespace io { |
| 47 namespace { | 48 namespace { |
| 48 | 49 |
| 49 // Each test repeats over several block sizes in order to test both cases | 50 // Each test repeats over several block sizes in order to test both cases |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 224 TEST(Printer, Death) { | 225 TEST(Printer, Death) { |
| 225 char buffer[8192]; | 226 char buffer[8192]; |
| 226 | 227 |
| 227 ArrayOutputStream output(buffer, sizeof(buffer)); | 228 ArrayOutputStream output(buffer, sizeof(buffer)); |
| 228 Printer printer(&output, '$'); | 229 Printer printer(&output, '$'); |
| 229 | 230 |
| 230 EXPECT_DEBUG_DEATH(printer.Print("$nosuchvar$"), "Undefined variable"); | 231 EXPECT_DEBUG_DEATH(printer.Print("$nosuchvar$"), "Undefined variable"); |
| 231 EXPECT_DEBUG_DEATH(printer.Print("$unclosed"), "Unclosed variable name"); | 232 EXPECT_DEBUG_DEATH(printer.Print("$unclosed"), "Unclosed variable name"); |
| 232 EXPECT_DEBUG_DEATH(printer.Outdent(), "without matching Indent"); | 233 EXPECT_DEBUG_DEATH(printer.Outdent(), "without matching Indent"); |
| 233 } | 234 } |
| 234 #endif // PROTOBUF__HAS_DEATH_TEST | 235 #endif // PROTOBUF_HAS_DEATH_TEST |
| 235 | 236 |
| 236 TEST(Printer, WriteFailurePartial) { | 237 TEST(Printer, WriteFailurePartial) { |
| 237 char buffer[17]; | 238 char buffer[17]; |
| 238 | 239 |
| 239 ArrayOutputStream output(buffer, sizeof(buffer)); | 240 ArrayOutputStream output(buffer, sizeof(buffer)); |
| 240 Printer printer(&output, '$'); | 241 Printer printer(&output, '$'); |
| 241 | 242 |
| 242 // Print 16 bytes to almost fill the buffer (should not fail). | 243 // Print 16 bytes to almost fill the buffer (should not fail). |
| 243 printer.Print("0123456789abcdef"); | 244 printer.Print("0123456789abcdef"); |
| 244 EXPECT_FALSE(printer.failed()); | 245 EXPECT_FALSE(printer.failed()); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 276 EXPECT_TRUE(printer.failed()); | 277 EXPECT_TRUE(printer.failed()); |
| 277 | 278 |
| 278 // Buffer should contain the first 16 bytes written. | 279 // Buffer should contain the first 16 bytes written. |
| 279 EXPECT_EQ("0123456789abcdef", string(buffer, sizeof(buffer))); | 280 EXPECT_EQ("0123456789abcdef", string(buffer, sizeof(buffer))); |
| 280 } | 281 } |
| 281 | 282 |
| 282 } // namespace | 283 } // namespace |
| 283 } // namespace io | 284 } // namespace io |
| 284 } // namespace protobuf | 285 } // namespace protobuf |
| 285 } // namespace google | 286 } // namespace google |
| OLD | NEW |