Commit 818c5eee authored by Feng Xiao's avatar Feng Xiao

Fix broken builds.

parent e96ff301
...@@ -19,7 +19,7 @@ m4/lt~obsolete.m4 ...@@ -19,7 +19,7 @@ m4/lt~obsolete.m4
autom4te.cache autom4te.cache
# downloaded files # downloaded files
gtest gmock
# in-tree configure-generated files # in-tree configure-generated files
Makefile Makefile
...@@ -47,6 +47,8 @@ any_test.pb.* ...@@ -47,6 +47,8 @@ any_test.pb.*
map*unittest.pb.* map*unittest.pb.*
unittest*.pb.* unittest*.pb.*
cpp_test*.pb.* cpp_test*.pb.*
src/google/protobuf/util/**/*.pb.cc
src/google/protobuf/util/**/*.pb.h
*.pyc *.pyc
*.egg-info *.egg-info
......
...@@ -12,9 +12,9 @@ environment: ...@@ -12,9 +12,9 @@ environment:
- BUILD_DLL: ON - BUILD_DLL: ON
install: install:
- ps: Start-FileDownload https://googletest.googlecode.com/files/gtest-1.7.0.zip - ps: Start-FileDownload https://googlemock.googlecode.com/files/gmock-1.7.0.zip
- 7z x gtest-1.7.0.zip - 7z x gmock-1.7.0.zip
- rename gtest-1.7.0 gtest - rename gmock-1.7.0 gmock
before_build: before_build:
- if %platform%==Win32 set generator=Visual Studio 12 - if %platform%==Win32 set generator=Visual Studio 12
...@@ -30,4 +30,5 @@ build_script: ...@@ -30,4 +30,5 @@ build_script:
- cd %configuration% - cd %configuration%
- tests.exe - tests.exe
skip_commits:
message: /.*\[skip appveyor\].*/
...@@ -89,6 +89,7 @@ copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\common.h include ...@@ -89,6 +89,7 @@ copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\common.h include
copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\fastmem.h include\google\protobuf\stubs\fastmem.h copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\fastmem.h include\google\protobuf\stubs\fastmem.h
copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\hash.h include\google\protobuf\stubs\hash.h copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\hash.h include\google\protobuf\stubs\hash.h
copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\once.h include\google\protobuf\stubs\once.h copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\once.h include\google\protobuf\stubs\once.h
copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\pbconfig.h include\google\protobuf\stubs\pbconfig.h
copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\platform_macros.h include\google\protobuf\stubs\platform_macros.h copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\platform_macros.h include\google\protobuf\stubs\platform_macros.h
copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\shared_ptr.h include\google\protobuf\stubs\shared_ptr.h copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\shared_ptr.h include\google\protobuf\stubs\shared_ptr.h
copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\singleton.h include\google\protobuf\stubs\singleton.h copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\singleton.h include\google\protobuf\stubs\singleton.h
......
...@@ -17,6 +17,7 @@ set(libprotobuf_lite_files ...@@ -17,6 +17,7 @@ set(libprotobuf_lite_files
${protobuf_source_dir}/src/google/protobuf/stubs/statusor.cc ${protobuf_source_dir}/src/google/protobuf/stubs/statusor.cc
${protobuf_source_dir}/src/google/protobuf/stubs/stringpiece.cc ${protobuf_source_dir}/src/google/protobuf/stubs/stringpiece.cc
${protobuf_source_dir}/src/google/protobuf/stubs/stringprintf.cc ${protobuf_source_dir}/src/google/protobuf/stubs/stringprintf.cc
${protobuf_source_dir}/src/google/protobuf/stubs/strutil.cc
${protobuf_source_dir}/src/google/protobuf/stubs/time.cc ${protobuf_source_dir}/src/google/protobuf/stubs/time.cc
${protobuf_source_dir}/src/google/protobuf/wire_format_lite.cc ${protobuf_source_dir}/src/google/protobuf/wire_format_lite.cc
) )
......
...@@ -26,7 +26,6 @@ set(libprotobuf_files ...@@ -26,7 +26,6 @@ set(libprotobuf_files
${protobuf_source_dir}/src/google/protobuf/struct.pb.cc ${protobuf_source_dir}/src/google/protobuf/struct.pb.cc
${protobuf_source_dir}/src/google/protobuf/stubs/mathlimits.cc ${protobuf_source_dir}/src/google/protobuf/stubs/mathlimits.cc
${protobuf_source_dir}/src/google/protobuf/stubs/structurally_valid.cc ${protobuf_source_dir}/src/google/protobuf/stubs/structurally_valid.cc
${protobuf_source_dir}/src/google/protobuf/stubs/strutil.cc
${protobuf_source_dir}/src/google/protobuf/stubs/substitute.cc ${protobuf_source_dir}/src/google/protobuf/stubs/substitute.cc
${protobuf_source_dir}/src/google/protobuf/text_format.cc ${protobuf_source_dir}/src/google/protobuf/text_format.cc
${protobuf_source_dir}/src/google/protobuf/timestamp.pb.cc ${protobuf_source_dir}/src/google/protobuf/timestamp.pb.cc
...@@ -44,6 +43,7 @@ set(libprotobuf_files ...@@ -44,6 +43,7 @@ set(libprotobuf_files
${protobuf_source_dir}/src/google/protobuf/util/internal/protostream_objectsource.cc ${protobuf_source_dir}/src/google/protobuf/util/internal/protostream_objectsource.cc
${protobuf_source_dir}/src/google/protobuf/util/internal/protostream_objectwriter.cc ${protobuf_source_dir}/src/google/protobuf/util/internal/protostream_objectwriter.cc
${protobuf_source_dir}/src/google/protobuf/util/internal/type_info.cc ${protobuf_source_dir}/src/google/protobuf/util/internal/type_info.cc
${protobuf_source_dir}/src/google/protobuf/util/internal/type_info_test_helper.cc
${protobuf_source_dir}/src/google/protobuf/util/internal/utility.cc ${protobuf_source_dir}/src/google/protobuf/util/internal/utility.cc
${protobuf_source_dir}/src/google/protobuf/util/json_util.cc ${protobuf_source_dir}/src/google/protobuf/util/json_util.cc
${protobuf_source_dir}/src/google/protobuf/util/message_differencer.cc ${protobuf_source_dir}/src/google/protobuf/util/message_differencer.cc
......
...@@ -2,13 +2,20 @@ if (NOT EXISTS "${PROJECT_SOURCE_DIR}/../gmock/CMakeLists.txt") ...@@ -2,13 +2,20 @@ if (NOT EXISTS "${PROJECT_SOURCE_DIR}/../gmock/CMakeLists.txt")
message(FATAL_ERROR "Cannot find gmock directory.") message(FATAL_ERROR "Cannot find gmock directory.")
endif() endif()
add_subdirectory(../gmock ${PROJECT_BINARY_DIR}/gmock)
include_directories( include_directories(
${protobuf_source_dir}/gmock
${protobuf_source_dir}/gmock/gtest
${protobuf_source_dir}/gmock/gtest/include ${protobuf_source_dir}/gmock/gtest/include
${protobuf_source_dir}/gmock/include ${protobuf_source_dir}/gmock/include
) )
add_library(gmock STATIC
${protobuf_source_dir}/gmock/src/gmock-all.cc
${protobuf_source_dir}/gmock/gtest/src/gtest-all.cc
)
add_library(gmock_main STATIC ${protobuf_source_dir}/gmock/src/gmock_main.cc)
target_link_libraries(gmock_main gmock)
set(lite_test_protos set(lite_test_protos
google/protobuf/map_lite_unittest.proto google/protobuf/map_lite_unittest.proto
google/protobuf/unittest_import_lite.proto google/protobuf/unittest_import_lite.proto
......
...@@ -170,6 +170,8 @@ libprotobuf_lite_la_SOURCES = \ ...@@ -170,6 +170,8 @@ libprotobuf_lite_la_SOURCES = \
google/protobuf/stubs/stringpiece.h \ google/protobuf/stubs/stringpiece.h \
google/protobuf/stubs/stringprintf.cc \ google/protobuf/stubs/stringprintf.cc \
google/protobuf/stubs/stringprintf.h \ google/protobuf/stubs/stringprintf.h \
google/protobuf/stubs/strutil.cc \
google/protobuf/stubs/strutil.h \
google/protobuf/stubs/time.cc \ google/protobuf/stubs/time.cc \
google/protobuf/stubs/time.h \ google/protobuf/stubs/time.h \
google/protobuf/arena.cc \ google/protobuf/arena.cc \
...@@ -210,8 +212,6 @@ libprotobuf_la_SOURCES = \ ...@@ -210,8 +212,6 @@ libprotobuf_la_SOURCES = \
google/protobuf/source_context.pb.cc \ google/protobuf/source_context.pb.cc \
google/protobuf/struct.pb.cc \ google/protobuf/struct.pb.cc \
google/protobuf/stubs/structurally_valid.cc \ google/protobuf/stubs/structurally_valid.cc \
google/protobuf/stubs/strutil.cc \
google/protobuf/stubs/strutil.h \
google/protobuf/stubs/substitute.cc \ google/protobuf/stubs/substitute.cc \
google/protobuf/stubs/substitute.h \ google/protobuf/stubs/substitute.h \
google/protobuf/text_format.cc \ google/protobuf/text_format.cc \
...@@ -235,6 +235,7 @@ libprotobuf_la_SOURCES = \ ...@@ -235,6 +235,7 @@ libprotobuf_la_SOURCES = \
google/protobuf/util/internal/default_value_objectwriter.h \ google/protobuf/util/internal/default_value_objectwriter.h \
google/protobuf/util/internal/error_listener.cc \ google/protobuf/util/internal/error_listener.cc \
google/protobuf/util/internal/error_listener.h \ google/protobuf/util/internal/error_listener.h \
google/protobuf/util/internal/expecting_objectwriter.h \
google/protobuf/util/internal/field_mask_utility.cc \ google/protobuf/util/internal/field_mask_utility.cc \
google/protobuf/util/internal/field_mask_utility.h \ google/protobuf/util/internal/field_mask_utility.h \
google/protobuf/util/internal/json_escaping.cc \ google/protobuf/util/internal/json_escaping.cc \
...@@ -244,16 +245,22 @@ libprotobuf_la_SOURCES = \ ...@@ -244,16 +245,22 @@ libprotobuf_la_SOURCES = \
google/protobuf/util/internal/json_stream_parser.cc \ google/protobuf/util/internal/json_stream_parser.cc \
google/protobuf/util/internal/json_stream_parser.h \ google/protobuf/util/internal/json_stream_parser.h \
google/protobuf/util/internal/location_tracker.h \ google/protobuf/util/internal/location_tracker.h \
google/protobuf/util/internal/mock_error_listener.h \
google/protobuf/util/internal/object_location_tracker.h \
google/protobuf/util/internal/object_source.h \ google/protobuf/util/internal/object_source.h \
google/protobuf/util/internal/object_writer.cc \ google/protobuf/util/internal/object_writer.cc \
google/protobuf/util/internal/object_writer.h \ google/protobuf/util/internal/object_writer.h \
google/protobuf/util/internal/object_writer.h \
google/protobuf/util/internal/protostream_objectsource.cc \ google/protobuf/util/internal/protostream_objectsource.cc \
google/protobuf/util/internal/protostream_objectsource.h \ google/protobuf/util/internal/protostream_objectsource.h \
google/protobuf/util/internal/protostream_objectwriter.cc \ google/protobuf/util/internal/protostream_objectwriter.cc \
google/protobuf/util/internal/protostream_objectwriter.h \ google/protobuf/util/internal/protostream_objectwriter.h \
google/protobuf/util/internal/snake2camel_objectwriter.h \
google/protobuf/util/internal/structured_objectwriter.h \
google/protobuf/util/internal/testdata \
google/protobuf/util/internal/type_info.cc \ google/protobuf/util/internal/type_info.cc \
google/protobuf/util/internal/type_info.h \ google/protobuf/util/internal/type_info.h \
google/protobuf/util/internal/type_info_test_helper.cc \
google/protobuf/util/internal/type_info_test_helper.h \
google/protobuf/util/internal/utility.cc \ google/protobuf/util/internal/utility.cc \
google/protobuf/util/internal/utility.h \ google/protobuf/util/internal/utility.h \
google/protobuf/util/json_util.cc \ google/protobuf/util/json_util.cc \
...@@ -619,11 +626,11 @@ COMMON_TEST_SOURCES = \ ...@@ -619,11 +626,11 @@ COMMON_TEST_SOURCES = \
check_PROGRAMS = protoc protobuf-test protobuf-lazy-descriptor-test \ check_PROGRAMS = protoc protobuf-test protobuf-lazy-descriptor-test \
protobuf-lite-test test_plugin $(GZCHECKPROGRAMS) protobuf-lite-test test_plugin $(GZCHECKPROGRAMS)
protobuf_test_LDADD = $(PTHREAD_LIBS) libprotobuf.la libprotoc.la \ protobuf_test_LDADD = $(PTHREAD_LIBS) libprotobuf.la libprotoc.la \
$(top_builddir)/gmock/gtest/lib/libgtest.la \ ../gmock/gtest/lib/libgtest.la \
$(top_builddir)/gmock/lib/libgmock.la \ ../gmock/lib/libgmock.la \
$(top_builddir)/gmock/lib/libgmock_main.la ../gmock/lib/libgmock_main.la
protobuf_test_CPPFLAGS = -I$(top_builddir)/gmock/gtest/include \ protobuf_test_CPPFLAGS = -I$(srcdir)/../gmock/gtest/include \
-I$(top_builddir)/gmock/include -I$(srcdir)/../gmock/include
# Disable optimization for tests unless the user explicitly asked for it, # Disable optimization for tests unless the user explicitly asked for it,
# since test_util.cc takes forever to compile with optimization (with GCC). # since test_util.cc takes forever to compile with optimization (with GCC).
# See configure.ac for more info. # See configure.ac for more info.
...@@ -699,11 +706,11 @@ nodist_protobuf_test_SOURCES = $(protoc_outputs) ...@@ -699,11 +706,11 @@ nodist_protobuf_test_SOURCES = $(protoc_outputs)
# Run cpp_unittest again with PROTOBUF_TEST_NO_DESCRIPTORS defined. # Run cpp_unittest again with PROTOBUF_TEST_NO_DESCRIPTORS defined.
protobuf_lazy_descriptor_test_LDADD = $(PTHREAD_LIBS) libprotobuf.la \ protobuf_lazy_descriptor_test_LDADD = $(PTHREAD_LIBS) libprotobuf.la \
libprotoc.la \ libprotoc.la \
$(top_builddir)/gmock/gtest/lib/libgtest.la \ ../gmock/gtest/lib/libgtest.la \
$(top_builddir)/gmock/lib/libgmock.la \ ../gmock/lib/libgmock.la \
$(top_builddir)/gmock/lib/libgmock_main.la ../gmock/lib/libgmock_main.la
protobuf_lazy_descriptor_test_CPPFLAGS = -I$(top_builddir)/gmock/include \ protobuf_lazy_descriptor_test_CPPFLAGS = -I$(srcdir)/../gmock/include \
-I$(top_builddir)/gmock/gtest/include \ -I$(srcdir)/../gmock/gtest/include \
-DPROTOBUF_TEST_NO_DESCRIPTORS -DPROTOBUF_TEST_NO_DESCRIPTORS
protobuf_lazy_descriptor_test_CXXFLAGS = $(NO_OPT_CXXFLAGS) protobuf_lazy_descriptor_test_CXXFLAGS = $(NO_OPT_CXXFLAGS)
protobuf_lazy_descriptor_test_SOURCES = \ protobuf_lazy_descriptor_test_SOURCES = \
...@@ -728,8 +735,8 @@ nodist_protobuf_lite_test_SOURCES = $(protoc_lite_outputs) ...@@ -728,8 +735,8 @@ nodist_protobuf_lite_test_SOURCES = $(protoc_lite_outputs)
# Test plugin binary. # Test plugin binary.
test_plugin_LDADD = $(PTHREAD_LIBS) libprotobuf.la libprotoc.la \ test_plugin_LDADD = $(PTHREAD_LIBS) libprotobuf.la libprotoc.la \
$(top_builddir)/gmock/gtest/lib/libgtest.la ../gmock/gtest/lib/libgtest.la
test_plugin_CPPFLAGS = -I$(top_builddir)/gmock/gtest/include test_plugin_CPPFLAGS = -I$(srcdir)/../gmock/gtest/include
test_plugin_SOURCES = \ test_plugin_SOURCES = \
google/protobuf/compiler/mock_code_generator.cc \ google/protobuf/compiler/mock_code_generator.cc \
google/protobuf/testing/file.cc \ google/protobuf/testing/file.cc \
......
...@@ -74,7 +74,7 @@ namespace strings { ...@@ -74,7 +74,7 @@ namespace strings {
// sink->Append(my_data.data(), my_data.size()); // sink->Append(my_data.data(), my_data.size());
// sink->Flush(); // sink->Flush();
// //
class ByteSink { class LIBPROTOBUF_EXPORT ByteSink {
public: public:
ByteSink() {} ByteSink() {}
virtual ~ByteSink() {} virtual ~ByteSink() {}
...@@ -103,7 +103,7 @@ class ByteSink { ...@@ -103,7 +103,7 @@ class ByteSink {
// source->Skip(data.length()); // source->Skip(data.length());
// } // }
// //
class ByteSource { class LIBPROTOBUF_EXPORT ByteSource {
public: public:
ByteSource() {} ByteSource() {}
virtual ~ByteSource() {} virtual ~ByteSource() {}
...@@ -159,7 +159,7 @@ class ByteSource { ...@@ -159,7 +159,7 @@ class ByteSource {
// sink.Append("hi", 2); // OK // sink.Append("hi", 2); // OK
// sink.Append(data, 100); // WOOPS! Overflows buf[10]. // sink.Append(data, 100); // WOOPS! Overflows buf[10].
// //
class UncheckedArrayByteSink : public ByteSink { class LIBPROTOBUF_EXPORT UncheckedArrayByteSink : public ByteSink {
public: public:
explicit UncheckedArrayByteSink(char* dest) : dest_(dest) {} explicit UncheckedArrayByteSink(char* dest) : dest_(dest) {}
virtual void Append(const char* data, size_t n); virtual void Append(const char* data, size_t n);
...@@ -187,7 +187,7 @@ class UncheckedArrayByteSink : public ByteSink { ...@@ -187,7 +187,7 @@ class UncheckedArrayByteSink : public ByteSink {
// sink.Append("hi", 2); // OK // sink.Append("hi", 2); // OK
// sink.Append(data, 100); // Will only write 8 more bytes // sink.Append(data, 100); // Will only write 8 more bytes
// //
class CheckedArrayByteSink : public ByteSink { class LIBPROTOBUF_EXPORT CheckedArrayByteSink : public ByteSink {
public: public:
CheckedArrayByteSink(char* outbuf, size_t capacity); CheckedArrayByteSink(char* outbuf, size_t capacity);
virtual void Append(const char* bytes, size_t n); virtual void Append(const char* bytes, size_t n);
...@@ -223,7 +223,7 @@ class CheckedArrayByteSink : public ByteSink { ...@@ -223,7 +223,7 @@ class CheckedArrayByteSink : public ByteSink {
// const char* buf = sink.GetBuffer(); // Ownership transferred // const char* buf = sink.GetBuffer(); // Ownership transferred
// delete[] buf; // delete[] buf;
// //
class GrowingArrayByteSink : public strings::ByteSink { class LIBPROTOBUF_EXPORT GrowingArrayByteSink : public strings::ByteSink {
public: public:
explicit GrowingArrayByteSink(size_t estimated_size); explicit GrowingArrayByteSink(size_t estimated_size);
virtual ~GrowingArrayByteSink(); virtual ~GrowingArrayByteSink();
...@@ -253,7 +253,7 @@ class GrowingArrayByteSink : public strings::ByteSink { ...@@ -253,7 +253,7 @@ class GrowingArrayByteSink : public strings::ByteSink {
// sink.Append("World", 5); // sink.Append("World", 5);
// assert(dest == "Hello World"); // assert(dest == "Hello World");
// //
class StringByteSink : public ByteSink { class LIBPROTOBUF_EXPORT StringByteSink : public ByteSink {
public: public:
explicit StringByteSink(string* dest) : dest_(dest) {} explicit StringByteSink(string* dest) : dest_(dest) {}
virtual void Append(const char* data, size_t n); virtual void Append(const char* data, size_t n);
...@@ -270,7 +270,7 @@ class StringByteSink : public ByteSink { ...@@ -270,7 +270,7 @@ class StringByteSink : public ByteSink {
// NullByteSink sink; // NullByteSink sink;
// sink.Append(data, data.size()); // All data ignored. // sink.Append(data, data.size()); // All data ignored.
// //
class NullByteSink : public ByteSink { class LIBPROTOBUF_EXPORT NullByteSink : public ByteSink {
public: public:
NullByteSink() {} NullByteSink() {}
virtual void Append(const char *data, size_t n) {} virtual void Append(const char *data, size_t n) {}
...@@ -292,7 +292,7 @@ class NullByteSink : public ByteSink { ...@@ -292,7 +292,7 @@ class NullByteSink : public ByteSink {
// assert(source.Available() == 5); // assert(source.Available() == 5);
// assert(source.Peek() == "Hello"); // assert(source.Peek() == "Hello");
// //
class ArrayByteSource : public ByteSource { class LIBPROTOBUF_EXPORT ArrayByteSource : public ByteSource {
public: public:
explicit ArrayByteSource(StringPiece s) : input_(s) {} explicit ArrayByteSource(StringPiece s) : input_(s) {}
...@@ -323,7 +323,7 @@ class ArrayByteSource : public ByteSource { ...@@ -323,7 +323,7 @@ class ArrayByteSource : public ByteSource {
// assert(limit.Available() == 5); // assert(limit.Available() == 5);
// assert(limit.Peek() == "Hello"); // assert(limit.Peek() == "Hello");
// //
class LimitByteSource : public ByteSource { class LIBPROTOBUF_EXPORT LimitByteSource : public ByteSource {
public: public:
// Returns at most "limit" bytes from "source". // Returns at most "limit" bytes from "source".
LimitByteSource(ByteSource* source, size_t limit); LimitByteSource(ByteSource* source, size_t limit);
......
...@@ -34,6 +34,7 @@ ...@@ -34,6 +34,7 @@
#include <google/protobuf/stubs/once.h> #include <google/protobuf/stubs/once.h>
#include <google/protobuf/stubs/status.h> #include <google/protobuf/stubs/status.h>
#include <google/protobuf/stubs/stringpiece.h> #include <google/protobuf/stubs/stringpiece.h>
#include <google/protobuf/stubs/strutil.h>
#include <stdio.h> #include <stdio.h>
#include <errno.h> #include <errno.h>
#include <vector> #include <vector>
...@@ -155,6 +156,16 @@ LogMessage& LogMessage::operator<<(const StringPiece& value) { ...@@ -155,6 +156,16 @@ LogMessage& LogMessage::operator<<(const StringPiece& value) {
return *this; return *this;
} }
LogMessage& LogMessage::operator<<(long long value) {
message_ += SimpleItoa(value);
return *this;
}
LogMessage& LogMessage::operator<<(unsigned long long value) {
message_ += SimpleItoa(value);
return *this;
}
LogMessage& LogMessage::operator<<( LogMessage& LogMessage::operator<<(
const ::google::protobuf::util::Status& status) { const ::google::protobuf::util::Status& status) {
message_ += status.ToString(); message_ += status.ToString();
...@@ -180,7 +191,7 @@ LogMessage& LogMessage::operator<<( ...@@ -180,7 +191,7 @@ LogMessage& LogMessage::operator<<(
DECLARE_STREAM_OPERATOR(char , "%c" ) DECLARE_STREAM_OPERATOR(char , "%c" )
DECLARE_STREAM_OPERATOR(int , "%d" ) DECLARE_STREAM_OPERATOR(int , "%d" )
DECLARE_STREAM_OPERATOR(uint , "%u" ) DECLARE_STREAM_OPERATOR(unsigned int , "%u" )
DECLARE_STREAM_OPERATOR(long , "%ld") DECLARE_STREAM_OPERATOR(long , "%ld")
DECLARE_STREAM_OPERATOR(unsigned long, "%lu") DECLARE_STREAM_OPERATOR(unsigned long, "%lu")
DECLARE_STREAM_OPERATOR(double , "%g" ) DECLARE_STREAM_OPERATOR(double , "%g" )
......
...@@ -50,8 +50,8 @@ ...@@ -50,8 +50,8 @@
#undef PROTOBUF_LITTLE_ENDIAN #undef PROTOBUF_LITTLE_ENDIAN
#ifdef _MSC_VER #ifdef _MSC_VER
#if defined(_M_IX86) && \ // Assuming windows is always little-endian.
!defined(PROTOBUF_DISABLE_LITTLE_ENDIAN_OPT_FOR_TEST) #if !defined(PROTOBUF_DISABLE_LITTLE_ENDIAN_OPT_FOR_TEST)
#define PROTOBUF_LITTLE_ENDIAN 1 #define PROTOBUF_LITTLE_ENDIAN 1
#endif #endif
#if _MSC_VER >= 1300 #if _MSC_VER >= 1300
...@@ -703,9 +703,11 @@ class LIBPROTOBUF_EXPORT LogMessage { ...@@ -703,9 +703,11 @@ class LIBPROTOBUF_EXPORT LogMessage {
LogMessage& operator<<(const char* value); LogMessage& operator<<(const char* value);
LogMessage& operator<<(char value); LogMessage& operator<<(char value);
LogMessage& operator<<(int value); LogMessage& operator<<(int value);
LogMessage& operator<<(uint value); LogMessage& operator<<(unsigned int value);
LogMessage& operator<<(long value); LogMessage& operator<<(long value);
LogMessage& operator<<(unsigned long value); LogMessage& operator<<(unsigned long value);
LogMessage& operator<<(long long value);
LogMessage& operator<<(unsigned long long value);
LogMessage& operator<<(double value); LogMessage& operator<<(double value);
LogMessage& operator<<(void* value); LogMessage& operator<<(void* value);
LogMessage& operator<<(const StringPiece& value); LogMessage& operator<<(const StringPiece& value);
......
...@@ -53,6 +53,8 @@ ...@@ -53,6 +53,8 @@
#include <cfloat> #include <cfloat>
#include <google/protobuf/stubs/common.h>
// ========================================================================= // // ========================================================================= //
// Useful integer and floating point limits and type traits. // Useful integer and floating point limits and type traits.
...@@ -162,7 +164,7 @@ template<typename T> struct MathLimits { ...@@ -162,7 +164,7 @@ template<typename T> struct MathLimits {
#define DECL_SIGNED_INT_LIMITS(IntType, UnsignedIntType) \ #define DECL_SIGNED_INT_LIMITS(IntType, UnsignedIntType) \
template<> \ template<> \
struct MathLimits<IntType> { \ struct LIBPROTOBUF_EXPORT MathLimits<IntType> { \
typedef IntType Type; \ typedef IntType Type; \
typedef UnsignedIntType UnsignedType; \ typedef UnsignedIntType UnsignedType; \
static const bool kIsSigned = true; \ static const bool kIsSigned = true; \
...@@ -182,7 +184,7 @@ struct MathLimits<IntType> { \ ...@@ -182,7 +184,7 @@ struct MathLimits<IntType> { \
#define DECL_UNSIGNED_INT_LIMITS(IntType) \ #define DECL_UNSIGNED_INT_LIMITS(IntType) \
template<> \ template<> \
struct MathLimits<IntType> { \ struct LIBPROTOBUF_EXPORT MathLimits<IntType> { \
typedef IntType Type; \ typedef IntType Type; \
typedef IntType UnsignedType; \ typedef IntType UnsignedType; \
static const bool kIsSigned = false; \ static const bool kIsSigned = false; \
...@@ -241,7 +243,7 @@ DECL_UNSIGNED_INT_LIMITS(unsigned long long int) ...@@ -241,7 +243,7 @@ DECL_UNSIGNED_INT_LIMITS(unsigned long long int)
// the global objects construction time. // the global objects construction time.
#define DECL_FP_LIMITS(FP_Type, PREFIX) \ #define DECL_FP_LIMITS(FP_Type, PREFIX) \
template<> \ template<> \
struct MathLimits<FP_Type> { \ struct LIBPROTOBUF_EXPORT MathLimits<FP_Type> { \
typedef FP_Type Type; \ typedef FP_Type Type; \
typedef FP_Type UnsignedType; \ typedef FP_Type UnsignedType; \
static const bool kIsSigned = true; \ static const bool kIsSigned = true; \
......
...@@ -29,8 +29,10 @@ ...@@ -29,8 +29,10 @@
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <google/protobuf/stubs/status.h> #include <google/protobuf/stubs/status.h>
#include <ostream>
#include <stdint.h> #include <stdint.h>
#include <stdio.h> #include <stdio.h>
#include <string>
#include <utility> #include <utility>
namespace google { namespace google {
......
...@@ -62,7 +62,7 @@ enum Code { ...@@ -62,7 +62,7 @@ enum Code {
}; };
} // namespace error } // namespace error
class Status { class LIBPROTOBUF_EXPORT Status {
public: public:
// Creates a "successful" status. // Creates a "successful" status.
Status(); Status();
...@@ -106,7 +106,7 @@ class Status { ...@@ -106,7 +106,7 @@ class Status {
}; };
// Prints a human-readable representation of 'x' to 'os'. // Prints a human-readable representation of 'x' to 'os'.
ostream& operator<<(ostream& os, const Status& x); LIBPROTOBUF_EXPORT ostream& operator<<(ostream& os, const Status& x);
#define EXPECT_OK(value) EXPECT_TRUE((value).ok()) #define EXPECT_OK(value) EXPECT_TRUE((value).ok())
......
...@@ -162,7 +162,7 @@ class StatusOr { ...@@ -162,7 +162,7 @@ class StatusOr {
namespace internal { namespace internal {
class StatusOrHelper { class LIBPROTOBUF_EXPORT StatusOrHelper {
public: public:
// Move type-agnostic error handling to the .cc. // Move type-agnostic error handling to the .cc.
static void Crash(const util::Status& status); static void Crash(const util::Status& status);
......
...@@ -174,7 +174,7 @@ typedef string::difference_type stringpiece_ssize_type; ...@@ -174,7 +174,7 @@ typedef string::difference_type stringpiece_ssize_type;
#define STRINGPIECE_CHECK_SIZE 0 #define STRINGPIECE_CHECK_SIZE 0
#endif #endif
class StringPiece { class LIBPROTOBUF_EXPORT StringPiece {
private: private:
const char* ptr_; const char* ptr_;
stringpiece_ssize_type length_; stringpiece_ssize_type length_;
...@@ -183,6 +183,9 @@ class StringPiece { ...@@ -183,6 +183,9 @@ class StringPiece {
// sizeof(stringpiece_ssize_type) may be smaller than sizeof(size_t). // sizeof(stringpiece_ssize_type) may be smaller than sizeof(size_t).
static stringpiece_ssize_type CheckedSsizeTFromSizeT(size_t size) { static stringpiece_ssize_type CheckedSsizeTFromSizeT(size_t size) {
#if STRINGPIECE_CHECK_SIZE > 0 #if STRINGPIECE_CHECK_SIZE > 0
#ifdef max
#undef max
#endif
if (size > static_cast<size_t>( if (size > static_cast<size_t>(
std::numeric_limits<stringpiece_ssize_type>::max())) { std::numeric_limits<stringpiece_ssize_type>::max())) {
// Some people grep for this message in logs // Some people grep for this message in logs
......
...@@ -38,6 +38,10 @@ ...@@ -38,6 +38,10 @@
#include <google/protobuf/testing/googletest.h> #include <google/protobuf/testing/googletest.h>
#include <gtest/gtest.h> #include <gtest/gtest.h>
#ifdef _WIN32
#define snprintf _snprintf
#endif
namespace google { namespace google {
namespace protobuf { namespace protobuf {
namespace { namespace {
...@@ -461,7 +465,7 @@ TEST(Base64, EscapeAndUnescape) { ...@@ -461,7 +465,7 @@ TEST(Base64, EscapeAndUnescape) {
encode_length); encode_length);
// Is it the expected encoded value? // Is it the expected encoded value?
EXPECT_STREQ(encode_buffer, base64_tests[i].cyphertext); ASSERT_STREQ(encode_buffer, base64_tests[i].cyphertext);
// If we encode it into a buffer of exactly the right length... // If we encode it into a buffer of exactly the right length...
memset(encode_buffer, 0, sizeof(encode_buffer)); memset(encode_buffer, 0, sizeof(encode_buffer));
...@@ -774,7 +778,6 @@ TEST(Base64, EscapeAndUnescape) { ...@@ -774,7 +778,6 @@ TEST(Base64, EscapeAndUnescape) {
// Now try the long strings, this tests the streaming // Now try the long strings, this tests the streaming
for (int i = 0; i < sizeof(base64_strings) / sizeof(base64_strings[0]); for (int i = 0; i < sizeof(base64_strings) / sizeof(base64_strings[0]);
++i) { ++i) {
const unsigned char* unsigned_plaintext = const unsigned char* unsigned_plaintext =
reinterpret_cast<const unsigned char*>(base64_strings[i].plaintext); reinterpret_cast<const unsigned char*>(base64_strings[i].plaintext);
int plain_length = strlen(base64_strings[i].plaintext); int plain_length = strlen(base64_strings[i].plaintext);
......
#include <google/protobuf/stubs/time.h> #include <google/protobuf/stubs/time.h>
#include <ctime>
#include <google/protobuf/stubs/stringprintf.h> #include <google/protobuf/stubs/stringprintf.h>
#include <google/protobuf/stubs/strutil.h> #include <google/protobuf/stubs/strutil.h>
......
...@@ -49,12 +49,12 @@ struct DateTime { ...@@ -49,12 +49,12 @@ struct DateTime {
// negative to represent time before 1970-01-01) to DateTime. Returns false // negative to represent time before 1970-01-01) to DateTime. Returns false
// if the timestamp is not in the range between 0001-01-01T00:00:00 and // if the timestamp is not in the range between 0001-01-01T00:00:00 and
// 9999-12-31T23:59:59. // 9999-12-31T23:59:59.
bool SecondsToDateTime(int64 seconds, DateTime* time); bool LIBPROTOBUF_EXPORT SecondsToDateTime(int64 seconds, DateTime* time);
// Converts DateTime to a timestamp (seconds since 1970-01-01T00:00:00). // Converts DateTime to a timestamp (seconds since 1970-01-01T00:00:00).
// Returns false if the DateTime is not valid or is not in the valid range. // Returns false if the DateTime is not valid or is not in the valid range.
bool DateTimeToSeconds(const DateTime& time, int64* seconds); bool LIBPROTOBUF_EXPORT DateTimeToSeconds(const DateTime& time, int64* seconds);
void GetCurrentTime(int64* seconds, int32* nanos); void LIBPROTOBUF_EXPORT GetCurrentTime(int64* seconds, int32* nanos);
// Formats a time string in RFC3339 fromat. // Formats a time string in RFC3339 fromat.
// //
...@@ -63,10 +63,10 @@ void GetCurrentTime(int64* seconds, int32* nanos); ...@@ -63,10 +63,10 @@ void GetCurrentTime(int64* seconds, int32* nanos);
// value. // value.
// //
// Note that "nanos" must in the range of [0, 999999999]. // Note that "nanos" must in the range of [0, 999999999].
string FormatTime(int64 seconds, int32 nanos); string LIBPROTOBUF_EXPORT FormatTime(int64 seconds, int32 nanos);
// Parses a time string. This method accepts RFC3339 date/time string with UTC // Parses a time string. This method accepts RFC3339 date/time string with UTC
// offset. For example, "2015-05-20T13:29:35.120-08:00". // offset. For example, "2015-05-20T13:29:35.120-08:00".
bool ParseTime(const string& vaule, int64* seconds, int32* nanos); bool LIBPROTOBUF_EXPORT ParseTime(const string& vaule, int64* seconds, int32* nanos);
} // namespace internal } // namespace internal
} // namespace protobuf } // namespace protobuf
......
...@@ -47,7 +47,7 @@ class FieldDescriptor; ...@@ -47,7 +47,7 @@ class FieldDescriptor;
namespace util { namespace util {
struct FieldContext; class FieldContext;
// Base class specifying the interface for comparing protocol buffer fields. // Base class specifying the interface for comparing protocol buffer fields.
// Regular users should consider using or subclassing DefaultFieldComparator // Regular users should consider using or subclassing DefaultFieldComparator
......
...@@ -57,7 +57,7 @@ namespace converter { ...@@ -57,7 +57,7 @@ namespace converter {
// ObjectWriter when EndObject() is called on the root object. It also writes // ObjectWriter when EndObject() is called on the root object. It also writes
// out all non-repeated primitive fields that haven't been explicitly rendered // out all non-repeated primitive fields that haven't been explicitly rendered
// with their default values (0 for numbers, "" for strings, etc). // with their default values (0 for numbers, "" for strings, etc).
class DefaultValueObjectWriter : public ObjectWriter { class LIBPROTOBUF_EXPORT DefaultValueObjectWriter : public ObjectWriter {
public: public:
DefaultValueObjectWriter(TypeResolver* type_resolver, DefaultValueObjectWriter(TypeResolver* type_resolver,
const google::protobuf::Type& type, const google::protobuf::Type& type,
......
...@@ -74,13 +74,13 @@ class MockObjectWriter : public ObjectWriter { ...@@ -74,13 +74,13 @@ class MockObjectWriter : public ObjectWriter {
MOCK_METHOD0(EndObject, ObjectWriter*()); MOCK_METHOD0(EndObject, ObjectWriter*());
MOCK_METHOD1(StartList, ObjectWriter*(StringPiece)); MOCK_METHOD1(StartList, ObjectWriter*(StringPiece));
MOCK_METHOD0(EndList, ObjectWriter*()); MOCK_METHOD0(EndList, ObjectWriter*());
MOCK_METHOD2(RenderBool, ObjectWriter*(StringPiece, const bool)); MOCK_METHOD2(RenderBool, ObjectWriter*(StringPiece, bool));
MOCK_METHOD2(RenderInt32, ObjectWriter*(StringPiece, const int32)); MOCK_METHOD2(RenderInt32, ObjectWriter*(StringPiece, int32));
MOCK_METHOD2(RenderUint32, ObjectWriter*(StringPiece, const uint32)); MOCK_METHOD2(RenderUint32, ObjectWriter*(StringPiece, uint32));
MOCK_METHOD2(RenderInt64, ObjectWriter*(StringPiece, const int64)); MOCK_METHOD2(RenderInt64, ObjectWriter*(StringPiece, int64));
MOCK_METHOD2(RenderUint64, ObjectWriter*(StringPiece, const uint64)); MOCK_METHOD2(RenderUint64, ObjectWriter*(StringPiece, uint64));
MOCK_METHOD2(RenderDouble, ObjectWriter*(StringPiece, const double)); MOCK_METHOD2(RenderDouble, ObjectWriter*(StringPiece, double));
MOCK_METHOD2(RenderFloat, ObjectWriter*(StringPiece, const float)); MOCK_METHOD2(RenderFloat, ObjectWriter*(StringPiece, float));
MOCK_METHOD2(RenderString, ObjectWriter*(StringPiece, StringPiece)); MOCK_METHOD2(RenderString, ObjectWriter*(StringPiece, StringPiece));
MOCK_METHOD2(RenderBytes, ObjectWriter*(StringPiece, StringPiece)); MOCK_METHOD2(RenderBytes, ObjectWriter*(StringPiece, StringPiece));
MOCK_METHOD1(RenderNull, ObjectWriter*(StringPiece)); MOCK_METHOD1(RenderNull, ObjectWriter*(StringPiece));
...@@ -122,7 +122,7 @@ class ExpectingObjectWriter : public ObjectWriter { ...@@ -122,7 +122,7 @@ class ExpectingObjectWriter : public ObjectWriter {
return this; return this;
} }
virtual ObjectWriter* RenderBool(StringPiece name, const bool value) { virtual ObjectWriter* RenderBool(StringPiece name, bool value) {
(name.empty() (name.empty()
? EXPECT_CALL(*mock_, RenderBool(IsEmpty(), TypedEq<bool>(value))) ? EXPECT_CALL(*mock_, RenderBool(IsEmpty(), TypedEq<bool>(value)))
: EXPECT_CALL(*mock_, RenderBool(StrEq(name.ToString()), : EXPECT_CALL(*mock_, RenderBool(StrEq(name.ToString()),
...@@ -132,7 +132,7 @@ class ExpectingObjectWriter : public ObjectWriter { ...@@ -132,7 +132,7 @@ class ExpectingObjectWriter : public ObjectWriter {
return this; return this;
} }
virtual ObjectWriter* RenderInt32(StringPiece name, const int32 value) { virtual ObjectWriter* RenderInt32(StringPiece name, int32 value) {
(name.empty() (name.empty()
? EXPECT_CALL(*mock_, RenderInt32(IsEmpty(), TypedEq<int32>(value))) ? EXPECT_CALL(*mock_, RenderInt32(IsEmpty(), TypedEq<int32>(value)))
: EXPECT_CALL(*mock_, RenderInt32(StrEq(name.ToString()), : EXPECT_CALL(*mock_, RenderInt32(StrEq(name.ToString()),
...@@ -142,7 +142,7 @@ class ExpectingObjectWriter : public ObjectWriter { ...@@ -142,7 +142,7 @@ class ExpectingObjectWriter : public ObjectWriter {
return this; return this;
} }
virtual ObjectWriter* RenderUint32(StringPiece name, const uint32 value) { virtual ObjectWriter* RenderUint32(StringPiece name, uint32 value) {
(name.empty() (name.empty()
? EXPECT_CALL(*mock_, RenderUint32(IsEmpty(), TypedEq<uint32>(value))) ? EXPECT_CALL(*mock_, RenderUint32(IsEmpty(), TypedEq<uint32>(value)))
: EXPECT_CALL(*mock_, RenderUint32(StrEq(name.ToString()), : EXPECT_CALL(*mock_, RenderUint32(StrEq(name.ToString()),
...@@ -152,7 +152,7 @@ class ExpectingObjectWriter : public ObjectWriter { ...@@ -152,7 +152,7 @@ class ExpectingObjectWriter : public ObjectWriter {
return this; return this;
} }
virtual ObjectWriter* RenderInt64(StringPiece name, const int64 value) { virtual ObjectWriter* RenderInt64(StringPiece name, int64 value) {
(name.empty() (name.empty()
? EXPECT_CALL(*mock_, RenderInt64(IsEmpty(), TypedEq<int64>(value))) ? EXPECT_CALL(*mock_, RenderInt64(IsEmpty(), TypedEq<int64>(value)))
: EXPECT_CALL(*mock_, RenderInt64(StrEq(name.ToString()), : EXPECT_CALL(*mock_, RenderInt64(StrEq(name.ToString()),
...@@ -162,7 +162,7 @@ class ExpectingObjectWriter : public ObjectWriter { ...@@ -162,7 +162,7 @@ class ExpectingObjectWriter : public ObjectWriter {
return this; return this;
} }
virtual ObjectWriter* RenderUint64(StringPiece name, const uint64 value) { virtual ObjectWriter* RenderUint64(StringPiece name, uint64 value) {
(name.empty() (name.empty()
? EXPECT_CALL(*mock_, RenderUint64(IsEmpty(), TypedEq<uint64>(value))) ? EXPECT_CALL(*mock_, RenderUint64(IsEmpty(), TypedEq<uint64>(value)))
: EXPECT_CALL(*mock_, RenderUint64(StrEq(name.ToString()), : EXPECT_CALL(*mock_, RenderUint64(StrEq(name.ToString()),
...@@ -172,7 +172,7 @@ class ExpectingObjectWriter : public ObjectWriter { ...@@ -172,7 +172,7 @@ class ExpectingObjectWriter : public ObjectWriter {
return this; return this;
} }
virtual ObjectWriter* RenderDouble(StringPiece name, const double value) { virtual ObjectWriter* RenderDouble(StringPiece name, double value) {
(name.empty() (name.empty()
? EXPECT_CALL(*mock_, RenderDouble(IsEmpty(), ? EXPECT_CALL(*mock_, RenderDouble(IsEmpty(),
NanSensitiveDoubleEq(value))) NanSensitiveDoubleEq(value)))
...@@ -183,7 +183,7 @@ class ExpectingObjectWriter : public ObjectWriter { ...@@ -183,7 +183,7 @@ class ExpectingObjectWriter : public ObjectWriter {
return this; return this;
} }
virtual ObjectWriter* RenderFloat(StringPiece name, const float value) { virtual ObjectWriter* RenderFloat(StringPiece name, float value) {
(name.empty() (name.empty()
? EXPECT_CALL(*mock_, RenderFloat(IsEmpty(), ? EXPECT_CALL(*mock_, RenderFloat(IsEmpty(),
NanSensitiveFloatEq(value))) NanSensitiveFloatEq(value)))
......
...@@ -80,22 +80,22 @@ JsonObjectWriter* JsonObjectWriter::EndList() { ...@@ -80,22 +80,22 @@ JsonObjectWriter* JsonObjectWriter::EndList() {
} }
JsonObjectWriter* JsonObjectWriter::RenderBool(StringPiece name, JsonObjectWriter* JsonObjectWriter::RenderBool(StringPiece name,
const bool value) { bool value) {
return RenderSimple(name, value ? "true" : "false"); return RenderSimple(name, value ? "true" : "false");
} }
JsonObjectWriter* JsonObjectWriter::RenderInt32(StringPiece name, JsonObjectWriter* JsonObjectWriter::RenderInt32(StringPiece name,
const int32 value) { int32 value) {
return RenderSimple(name, SimpleItoa(value)); return RenderSimple(name, SimpleItoa(value));
} }
JsonObjectWriter* JsonObjectWriter::RenderUint32(StringPiece name, JsonObjectWriter* JsonObjectWriter::RenderUint32(StringPiece name,
const uint32 value) { uint32 value) {
return RenderSimple(name, SimpleItoa(value)); return RenderSimple(name, SimpleItoa(value));
} }
JsonObjectWriter* JsonObjectWriter::RenderInt64(StringPiece name, JsonObjectWriter* JsonObjectWriter::RenderInt64(StringPiece name,
const int64 value) { int64 value) {
WritePrefix(name); WritePrefix(name);
WriteChar('"'); WriteChar('"');
stream_->WriteString(SimpleItoa(value)); stream_->WriteString(SimpleItoa(value));
...@@ -104,7 +104,7 @@ JsonObjectWriter* JsonObjectWriter::RenderInt64(StringPiece name, ...@@ -104,7 +104,7 @@ JsonObjectWriter* JsonObjectWriter::RenderInt64(StringPiece name,
} }
JsonObjectWriter* JsonObjectWriter::RenderUint64(StringPiece name, JsonObjectWriter* JsonObjectWriter::RenderUint64(StringPiece name,
const uint64 value) { uint64 value) {
WritePrefix(name); WritePrefix(name);
WriteChar('"'); WriteChar('"');
stream_->WriteString(SimpleItoa(value)); stream_->WriteString(SimpleItoa(value));
...@@ -113,7 +113,7 @@ JsonObjectWriter* JsonObjectWriter::RenderUint64(StringPiece name, ...@@ -113,7 +113,7 @@ JsonObjectWriter* JsonObjectWriter::RenderUint64(StringPiece name,
} }
JsonObjectWriter* JsonObjectWriter::RenderDouble(StringPiece name, JsonObjectWriter* JsonObjectWriter::RenderDouble(StringPiece name,
const double value) { double value) {
if (isfinite(value)) return RenderSimple(name, SimpleDtoa(value)); if (isfinite(value)) return RenderSimple(name, SimpleDtoa(value));
// Render quoted with NaN/Infinity-aware DoubleAsString. // Render quoted with NaN/Infinity-aware DoubleAsString.
...@@ -121,7 +121,7 @@ JsonObjectWriter* JsonObjectWriter::RenderDouble(StringPiece name, ...@@ -121,7 +121,7 @@ JsonObjectWriter* JsonObjectWriter::RenderDouble(StringPiece name,
} }
JsonObjectWriter* JsonObjectWriter::RenderFloat(StringPiece name, JsonObjectWriter* JsonObjectWriter::RenderFloat(StringPiece name,
const float value) { float value) {
if (isfinite(value)) return RenderSimple(name, SimpleFtoa(value)); if (isfinite(value)) return RenderSimple(name, SimpleFtoa(value));
// Render quoted with NaN/Infinity-aware FloatAsString. // Render quoted with NaN/Infinity-aware FloatAsString.
......
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
#include <google/protobuf/util/internal/json_objectwriter.h> #include <google/protobuf/util/internal/json_objectwriter.h>
#include <google/protobuf/io/zero_copy_stream_impl_lite.h> #include <google/protobuf/io/zero_copy_stream_impl_lite.h>
#include <google/protobuf/util/internal/utility.h>
#include <gtest/gtest.h> #include <gtest/gtest.h>
namespace google { namespace google {
...@@ -152,8 +153,8 @@ TEST_F(JsonObjectWriterTest, RenderPrimitives) { ...@@ -152,8 +153,8 @@ TEST_F(JsonObjectWriterTest, RenderPrimitives) {
->EndObject(); ->EndObject();
EXPECT_EQ( EXPECT_EQ(
"{\"bool\":true," "{\"bool\":true,"
"\"double\":1.7976931348623157e+308," "\"double\":" + ValueAsString<double>(1.7976931348623157e+308) + ","
"\"float\":3.4028235e+38," "\"float\":" + ValueAsString<float>(3.4028235e+38) + ","
"\"int\":-2147483648," "\"int\":-2147483648,"
"\"long\":\"-9223372036854775808\"," "\"long\":\"-9223372036854775808\","
"\"bytes\":\"YWJyYWNhZGFicmE=\"," "\"bytes\":\"YWJyYWNhZGFicmE=\","
......
...@@ -337,14 +337,19 @@ TEST_F(JsonStreamParserTest, ObjectValues) { ...@@ -337,14 +337,19 @@ TEST_F(JsonStreamParserTest, ObjectValues) {
} }
} }
#ifndef _MSC_VER
// - unicode handling in strings // - unicode handling in strings
TEST_F(JsonStreamParserTest, UnicodeEscaping) { TEST_F(JsonStreamParserTest, UnicodeEscaping) {
StringPiece str = "[\"\\u0639\\u0631\\u0628\\u0649\"]"; StringPiece str = "[\"\\u0639\\u0631\\u0628\\u0649\"]";
for (int i = 0; i <= str.length(); ++i) { for (int i = 0; i <= str.length(); ++i) {
// TODO(xiaofeng): Figure out what default encoding to use for JSON strings.
// In protobuf we use UTF-8 for strings, but for JSON we probably should allow
// different encodings?
ow_.StartList("")->RenderString("", "\u0639\u0631\u0628\u0649")->EndList(); ow_.StartList("")->RenderString("", "\u0639\u0631\u0628\u0649")->EndList();
DoTest(str, i); DoTest(str, i);
} }
} }
#endif
// - ascii escaping (\b, \f, \n, \r, \t, \v) // - ascii escaping (\b, \f, \n, \r, \t, \v)
TEST_F(JsonStreamParserTest, AsciiEscaping) { TEST_F(JsonStreamParserTest, AsciiEscaping) {
......
...@@ -141,13 +141,13 @@ class ProtostreamObjectSourceTest ...@@ -141,13 +141,13 @@ class ProtostreamObjectSourceTest
->RenderInt32("", 3208) ->RenderInt32("", 3208)
->EndList() ->EndList()
->StartList("rep_fix64") ->StartList("rep_fix64")
->RenderUint64("", bit_cast<uint64>(6401L)) ->RenderUint64("", bit_cast<uint64>(6401LL))
->RenderUint64("", bit_cast<uint64>(0L)) ->RenderUint64("", bit_cast<uint64>(0LL))
->EndList() ->EndList()
->StartList("rep_u64") ->StartList("rep_u64")
->RenderUint64("", bit_cast<uint64>(0L)) ->RenderUint64("", bit_cast<uint64>(0LL))
->RenderUint64("", bit_cast<uint64>(6402L)) ->RenderUint64("", bit_cast<uint64>(6402LL))
->RenderUint64("", bit_cast<uint64>(6403L)) ->RenderUint64("", bit_cast<uint64>(6403LL))
->EndList() ->EndList()
->StartList("rep_i64") ->StartList("rep_i64")
->RenderInt64("", 6404L) ->RenderInt64("", 6404L)
...@@ -297,8 +297,8 @@ TEST_P(ProtostreamObjectSourceTest, Primitives) { ...@@ -297,8 +297,8 @@ TEST_P(ProtostreamObjectSourceTest, Primitives) {
->RenderInt32("i32", 3203) ->RenderInt32("i32", 3203)
->RenderInt32("sf32", 3204) ->RenderInt32("sf32", 3204)
->RenderInt32("s32", 3205) ->RenderInt32("s32", 3205)
->RenderUint64("fix64", bit_cast<uint64>(6401L)) ->RenderUint64("fix64", bit_cast<uint64>(6401LL))
->RenderUint64("u64", bit_cast<uint64>(6402L)) ->RenderUint64("u64", bit_cast<uint64>(6402LL))
->RenderInt64("i64", 6403L) ->RenderInt64("i64", 6403L)
->RenderInt64("sf64", 6404L) ->RenderInt64("sf64", 6404L)
->RenderInt64("s64", 6405L) ->RenderInt64("s64", 6405L)
...@@ -338,7 +338,7 @@ TEST_P(ProtostreamObjectSourceTest, NestedMessage) { ...@@ -338,7 +338,7 @@ TEST_P(ProtostreamObjectSourceTest, NestedMessage) {
ow_.StartObject("") ow_.StartObject("")
->RenderString("title", "My Book") ->RenderString("title", "My Book")
->StartObject("author") ->StartObject("author")
->RenderUint64("id", bit_cast<uint64>(101L)) ->RenderUint64("id", bit_cast<uint64>(101LL))
->RenderString("name", "Tolstoy") ->RenderString("name", "Tolstoy")
->EndObject() ->EndObject()
->EndObject(); ->EndObject();
......
...@@ -83,31 +83,31 @@ class LIBPROTOBUF_EXPORT ProtoStreamObjectWriter : public StructuredObjectWriter ...@@ -83,31 +83,31 @@ class LIBPROTOBUF_EXPORT ProtoStreamObjectWriter : public StructuredObjectWriter
virtual ProtoStreamObjectWriter* StartList(StringPiece name); virtual ProtoStreamObjectWriter* StartList(StringPiece name);
virtual ProtoStreamObjectWriter* EndList(); virtual ProtoStreamObjectWriter* EndList();
virtual ProtoStreamObjectWriter* RenderBool(StringPiece name, virtual ProtoStreamObjectWriter* RenderBool(StringPiece name,
const bool value) { bool value) {
return RenderDataPiece(name, DataPiece(value)); return RenderDataPiece(name, DataPiece(value));
} }
virtual ProtoStreamObjectWriter* RenderInt32(StringPiece name, virtual ProtoStreamObjectWriter* RenderInt32(StringPiece name,
const int32 value) { int32 value) {
return RenderDataPiece(name, DataPiece(value)); return RenderDataPiece(name, DataPiece(value));
} }
virtual ProtoStreamObjectWriter* RenderUint32(StringPiece name, virtual ProtoStreamObjectWriter* RenderUint32(StringPiece name,
const uint32 value) { uint32 value) {
return RenderDataPiece(name, DataPiece(value)); return RenderDataPiece(name, DataPiece(value));
} }
virtual ProtoStreamObjectWriter* RenderInt64(StringPiece name, virtual ProtoStreamObjectWriter* RenderInt64(StringPiece name,
const int64 value) { int64 value) {
return RenderDataPiece(name, DataPiece(value)); return RenderDataPiece(name, DataPiece(value));
} }
virtual ProtoStreamObjectWriter* RenderUint64(StringPiece name, virtual ProtoStreamObjectWriter* RenderUint64(StringPiece name,
const uint64 value) { uint64 value) {
return RenderDataPiece(name, DataPiece(value)); return RenderDataPiece(name, DataPiece(value));
} }
virtual ProtoStreamObjectWriter* RenderDouble(StringPiece name, virtual ProtoStreamObjectWriter* RenderDouble(StringPiece name,
const double value) { double value) {
return RenderDataPiece(name, DataPiece(value)); return RenderDataPiece(name, DataPiece(value));
} }
virtual ProtoStreamObjectWriter* RenderFloat(StringPiece name, virtual ProtoStreamObjectWriter* RenderFloat(StringPiece name,
const float value) { float value) {
return RenderDataPiece(name, DataPiece(value)); return RenderDataPiece(name, DataPiece(value));
} }
virtual ProtoStreamObjectWriter* RenderString(StringPiece name, virtual ProtoStreamObjectWriter* RenderString(StringPiece name,
......
...@@ -44,7 +44,7 @@ namespace util { ...@@ -44,7 +44,7 @@ namespace util {
namespace converter { namespace converter {
// Internal helper class for type resolving. Note that this class is not // Internal helper class for type resolving. Note that this class is not
// thread-safe and should only be accessed in one thread. // thread-safe and should only be accessed in one thread.
class TypeInfo { class LIBPROTOBUF_EXPORT TypeInfo {
public: public:
TypeInfo() {} TypeInfo() {}
virtual ~TypeInfo() {} virtual ~TypeInfo() {}
......
...@@ -66,25 +66,25 @@ namespace converter { ...@@ -66,25 +66,25 @@ namespace converter {
// Finds the tech option identified by option_name. Parses the boolean value and // Finds the tech option identified by option_name. Parses the boolean value and
// returns it. // returns it.
// When the option with the given name is not found, default_value is returned. // When the option with the given name is not found, default_value is returned.
bool GetBoolOptionOrDefault( LIBPROTOBUF_EXPORT bool GetBoolOptionOrDefault(
const google::protobuf::RepeatedPtrField<google::protobuf::Option>& options, const google::protobuf::RepeatedPtrField<google::protobuf::Option>& options,
const string& option_name, bool default_value); const string& option_name, bool default_value);
// Returns int64 option value. If the option isn't found, returns the // Returns int64 option value. If the option isn't found, returns the
// default_value. // default_value.
int64 GetInt64OptionOrDefault( LIBPROTOBUF_EXPORT int64 GetInt64OptionOrDefault(
const google::protobuf::RepeatedPtrField<google::protobuf::Option>& options, const google::protobuf::RepeatedPtrField<google::protobuf::Option>& options,
const string& option_name, int64 default_value); const string& option_name, int64 default_value);
// Returns double option value. If the option isn't found, returns the // Returns double option value. If the option isn't found, returns the
// default_value. // default_value.
double GetDoubleOptionOrDefault( LIBPROTOBUF_EXPORT double GetDoubleOptionOrDefault(
const google::protobuf::RepeatedPtrField<google::protobuf::Option>& options, const google::protobuf::RepeatedPtrField<google::protobuf::Option>& options,
const string& option_name, double default_value); const string& option_name, double default_value);
// Returns string option value. If the option isn't found, returns the // Returns string option value. If the option isn't found, returns the
// default_value. // default_value.
string GetStringOptionOrDefault( LIBPROTOBUF_EXPORT string GetStringOptionOrDefault(
const google::protobuf::RepeatedPtrField<google::protobuf::Option>& options, const google::protobuf::RepeatedPtrField<google::protobuf::Option>& options,
const string& option_name, const string& default_value); const string& option_name, const string& default_value);
...@@ -92,20 +92,20 @@ string GetStringOptionOrDefault( ...@@ -92,20 +92,20 @@ string GetStringOptionOrDefault(
// TODO(skarvaje): Make these utilities dealing with Any types more generic, // TODO(skarvaje): Make these utilities dealing with Any types more generic,
// add more error checking and move to a more public/sharable location so others // add more error checking and move to a more public/sharable location so others
// can use. // can use.
bool GetBoolFromAny(const google::protobuf::Any& any); LIBPROTOBUF_EXPORT bool GetBoolFromAny(const google::protobuf::Any& any);
// Returns int64 value contained in Any type. // Returns int64 value contained in Any type.
int64 GetInt64FromAny(const google::protobuf::Any& any); LIBPROTOBUF_EXPORT int64 GetInt64FromAny(const google::protobuf::Any& any);
// Returns double value contained in Any type. // Returns double value contained in Any type.
double GetDoubleFromAny(const google::protobuf::Any& any); LIBPROTOBUF_EXPORT double GetDoubleFromAny(const google::protobuf::Any& any);
// Returns string value contained in Any type. // Returns string value contained in Any type.
string GetStringFromAny(const google::protobuf::Any& any); LIBPROTOBUF_EXPORT string GetStringFromAny(const google::protobuf::Any& any);
// Returns the type string without the url prefix. e.g.: If the passed type is // Returns the type string without the url prefix. e.g.: If the passed type is
// 'type.googleapis.com/tech.type.Bool', the returned value is 'tech.type.Bool'. // 'type.googleapis.com/tech.type.Bool', the returned value is 'tech.type.Bool'.
const StringPiece GetTypeWithoutUrl(StringPiece type_url); LIBPROTOBUF_EXPORT const StringPiece GetTypeWithoutUrl(StringPiece type_url);
// Returns the simple_type with the base type url (kTypeServiceBaseUrl) // Returns the simple_type with the base type url (kTypeServiceBaseUrl)
// prefixed. // prefixed.
...@@ -113,52 +113,52 @@ const StringPiece GetTypeWithoutUrl(StringPiece type_url); ...@@ -113,52 +113,52 @@ const StringPiece GetTypeWithoutUrl(StringPiece type_url);
// E.g: // E.g:
// GetFullTypeWithUrl("google.protobuf.Timestamp") returns the string // GetFullTypeWithUrl("google.protobuf.Timestamp") returns the string
// "type.googleapis.com/google.protobuf.Timestamp". // "type.googleapis.com/google.protobuf.Timestamp".
const string GetFullTypeWithUrl(StringPiece simple_type); LIBPROTOBUF_EXPORT const string GetFullTypeWithUrl(StringPiece simple_type);
// Finds and returns option identified by name and option_name within the // Finds and returns option identified by name and option_name within the
// provided map. Returns NULL if none found. // provided map. Returns NULL if none found.
const google::protobuf::Option* FindOptionOrNull( LIBPROTOBUF_EXPORT const google::protobuf::Option* FindOptionOrNull(
const google::protobuf::RepeatedPtrField<google::protobuf::Option>& options, const google::protobuf::RepeatedPtrField<google::protobuf::Option>& options,
const string& option_name); const string& option_name);
// Finds and returns the field identified by field_name in the passed tech Type // Finds and returns the field identified by field_name in the passed tech Type
// object. Returns NULL if none found. // object. Returns NULL if none found.
const google::protobuf::Field* FindFieldInTypeOrNull( LIBPROTOBUF_EXPORT const google::protobuf::Field* FindFieldInTypeOrNull(
const google::protobuf::Type* type, StringPiece field_name); const google::protobuf::Type* type, StringPiece field_name);
// Finds and returns the EnumValue identified by enum_name in the passed tech // Finds and returns the EnumValue identified by enum_name in the passed tech
// Enum object. Returns NULL if none found. // Enum object. Returns NULL if none found.
const google::protobuf::EnumValue* FindEnumValueByNameOrNull( LIBPROTOBUF_EXPORT const google::protobuf::EnumValue* FindEnumValueByNameOrNull(
const google::protobuf::Enum* enum_type, StringPiece enum_name); const google::protobuf::Enum* enum_type, StringPiece enum_name);
// Finds and returns the EnumValue identified by value in the passed tech // Finds and returns the EnumValue identified by value in the passed tech
// Enum object. Returns NULL if none found. // Enum object. Returns NULL if none found.
const google::protobuf::EnumValue* FindEnumValueByNumberOrNull( LIBPROTOBUF_EXPORT const google::protobuf::EnumValue* FindEnumValueByNumberOrNull(
const google::protobuf::Enum* enum_type, int32 value); const google::protobuf::Enum* enum_type, int32 value);
// Converts input to camel-case and returns it. // Converts input to camel-case and returns it.
// Tests are in wrappers/translator/snake2camel_objectwriter_test.cc // Tests are in wrappers/translator/snake2camel_objectwriter_test.cc
// TODO(skarvaje): Isolate tests for this function and put them in // TODO(skarvaje): Isolate tests for this function and put them in
// utility_test.cc // utility_test.cc
string ToCamelCase(const StringPiece input); LIBPROTOBUF_EXPORT string ToCamelCase(const StringPiece input);
// Converts input to snake_case and returns it. // Converts input to snake_case and returns it.
string ToSnakeCase(StringPiece input); LIBPROTOBUF_EXPORT string ToSnakeCase(StringPiece input);
// Returns true if type_name represents a well-known type. // Returns true if type_name represents a well-known type.
bool IsWellKnownType(const string& type_name); LIBPROTOBUF_EXPORT bool IsWellKnownType(const string& type_name);
// Returns true if 'bool_string' represents a valid boolean value. Only "true", // Returns true if 'bool_string' represents a valid boolean value. Only "true",
// "false", "0" and "1" are allowed. // "false", "0" and "1" are allowed.
bool IsValidBoolString(const string& bool_string); LIBPROTOBUF_EXPORT bool IsValidBoolString(const string& bool_string);
// Returns true if "field" is a protobuf map field based on its type. // Returns true if "field" is a protobuf map field based on its type.
bool IsMap(const google::protobuf::Field& field, bool IsMap(const google::protobuf::Field& field,
const google::protobuf::Type& type); const google::protobuf::Type& type);
// Infinity/NaN-aware conversion to string. // Infinity/NaN-aware conversion to string.
string DoubleAsString(double value); LIBPROTOBUF_EXPORT string DoubleAsString(double value);
string FloatAsString(float value); LIBPROTOBUF_EXPORT string FloatAsString(float value);
// Convert from int32, int64, uint32, uint64, double or float to string. // Convert from int32, int64, uint32, uint64, double or float to string.
template <typename T> template <typename T>
...@@ -178,7 +178,7 @@ inline string ValueAsString(double value) { ...@@ -178,7 +178,7 @@ inline string ValueAsString(double value) {
// Converts a string to float. Unlike safe_strtof, conversion will fail if the // Converts a string to float. Unlike safe_strtof, conversion will fail if the
// value fits into double but not float (e.g., DBL_MAX). // value fits into double but not float (e.g., DBL_MAX).
bool SafeStrToFloat(StringPiece str, float* value); LIBPROTOBUF_EXPORT bool SafeStrToFloat(StringPiece str, float* value);
} // namespace converter } // namespace converter
} // namespace util } // namespace util
} // namespace protobuf } // namespace protobuf
......
...@@ -44,7 +44,7 @@ class ZeroCopyOutputStream; ...@@ -44,7 +44,7 @@ class ZeroCopyOutputStream;
} // namespace io } // namespace io
namespace util { namespace util {
struct JsonOptions { struct LIBPROTOBUF_EXPORT JsonOptions {
// Whether to add spaces, line breaks and indentation to make the JSON output // Whether to add spaces, line breaks and indentation to make the JSON output
// easy to read. // easy to read.
bool add_whitespace; bool add_whitespace;
...@@ -65,7 +65,8 @@ struct JsonOptions { ...@@ -65,7 +65,8 @@ struct JsonOptions {
// 2. input is not valid protobuf wire format, or conflicts with the type // 2. input is not valid protobuf wire format, or conflicts with the type
// information returned by TypeResolver. // information returned by TypeResolver.
// Note that unknown fields will be discarded silently. // Note that unknown fields will be discarded silently.
util::Status BinaryToJsonStream(TypeResolver* resolver, LIBPROTOBUF_EXPORT util::Status BinaryToJsonStream(
TypeResolver* resolver,
const string& type_url, const string& type_url,
io::ZeroCopyInputStream* binary_input, io::ZeroCopyInputStream* binary_input,
io::ZeroCopyOutputStream* json_output, io::ZeroCopyOutputStream* json_output,
...@@ -79,7 +80,8 @@ inline util::Status BinaryToJsonStream( ...@@ -79,7 +80,8 @@ inline util::Status BinaryToJsonStream(
JsonOptions()); JsonOptions());
} }
util::Status BinaryToJsonString(TypeResolver* resolver, LIBPROTOBUF_EXPORT util::Status BinaryToJsonString(
TypeResolver* resolver,
const string& type_url, const string& type_url,
const string& binary_input, const string& binary_input,
string* json_output, string* json_output,
...@@ -99,12 +101,14 @@ inline util::Status BinaryToJsonString(TypeResolver* resolver, ...@@ -99,12 +101,14 @@ inline util::Status BinaryToJsonString(TypeResolver* resolver,
// 2. input is not valid JSON format, or conflicts with the type // 2. input is not valid JSON format, or conflicts with the type
// information returned by TypeResolver. // information returned by TypeResolver.
// 3. input has unknown fields. // 3. input has unknown fields.
util::Status JsonToBinaryStream(TypeResolver* resolver, LIBPROTOBUF_EXPORT util::Status JsonToBinaryStream(
TypeResolver* resolver,
const string& type_url, const string& type_url,
io::ZeroCopyInputStream* json_input, io::ZeroCopyInputStream* json_input,
io::ZeroCopyOutputStream* binary_output); io::ZeroCopyOutputStream* binary_output);
util::Status JsonToBinaryString(TypeResolver* resolver, LIBPROTOBUF_EXPORT util::Status JsonToBinaryString(
TypeResolver* resolver,
const string& type_url, const string& type_url,
const string& json_input, const string& json_input,
string* binary_output); string* binary_output);
......
...@@ -87,10 +87,10 @@ class MessageDifferencer::MultipleFieldsMapKeyComparator ...@@ -87,10 +87,10 @@ class MessageDifferencer::MultipleFieldsMapKeyComparator
key_field_path.push_back(key); key_field_path.push_back(key);
key_field_paths_.push_back(key_field_path); key_field_paths_.push_back(key_field_path);
} }
bool IsMatch( virtual bool IsMatch(
const Message& message1, const Message& message1,
const Message& message2, const Message& message2,
const vector<SpecificField>& parent_fields) const override { const vector<SpecificField>& parent_fields) const {
for (int i = 0; i < key_field_paths_.size(); ++i) { for (int i = 0; i < key_field_paths_.size(); ++i) {
if (!IsMatchInternal(message1, message2, parent_fields, if (!IsMatchInternal(message1, message2, parent_fields,
key_field_paths_[i], 0)) { key_field_paths_[i], 0)) {
......
...@@ -42,7 +42,7 @@ class TypeResolver; ...@@ -42,7 +42,7 @@ class TypeResolver;
// Creates a TypeResolver that serves type information in the given descriptor // Creates a TypeResolver that serves type information in the given descriptor
// pool. Caller takes ownership of the returned TypeResolver. // pool. Caller takes ownership of the returned TypeResolver.
TypeResolver* NewTypeResolverForDescriptorPool( LIBPROTOBUF_EXPORT TypeResolver* NewTypeResolverForDescriptorPool(
const string& url_prefix, const DescriptorPool* pool); const string& url_prefix, const DescriptorPool* pool);
} // namespace util } // namespace util
......
...@@ -81,7 +81,7 @@ class DescriptorPoolTypeResolverTest : public testing::Test { ...@@ -81,7 +81,7 @@ class DescriptorPoolTypeResolverTest : public testing::Test {
} }
bool HasField(const Type& type, Field::Cardinality cardinality, bool HasField(const Type& type, Field::Cardinality cardinality,
Field::Field::Kind kind, const string& name, int number) { Field::Kind kind, const string& name, int number) {
const Field* field = FindField(type, name); const Field* field = FindField(type, name);
if (field == NULL) { if (field == NULL) {
return false; return false;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment