Merge pull request #488 from AustinSchuh/ruby_test_fix

Modified FindRubyTestDir to use GOOGLE_THIRD_PARTY_PROTOBUF
diff --git a/.gitignore b/.gitignore
index 8ea85af..52c92df 100644
--- a/.gitignore
+++ b/.gitignore
@@ -27,7 +27,6 @@
 /config.h
 config.log
 config.status
-pbconfig.h
 
 libtool
 protobuf-lite.pc
diff --git a/Makefile.am b/Makefile.am
index cc49d6f..0eb8020 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -743,7 +743,6 @@
   LICENSE                              \
   CONTRIBUTORS.txt                     \
   CHANGES.txt                          \
-  config.h.include                     \
   cmake/CMakeLists.txt                 \
   cmake/config.h.in                    \
   cmake/find_hash_map.cmake            \
diff --git a/appveyor.yml b/appveyor.yml
new file mode 100644
index 0000000..9186223
--- /dev/null
+++ b/appveyor.yml
@@ -0,0 +1,33 @@
+# Only test one combination: "Visual Studio 12 + Win64 + Debug + DLL". We can

+# test more combinations but AppVeyor just takes too long to finish (each

+# combination takes ~15mins).

+platform:

+  - Win64

+

+configuration:

+  - Debug

+

+environment:

+  matrix:

+    - BUILD_DLL: ON

+

+install:

+  - ps: Start-FileDownload https://googletest.googlecode.com/files/gtest-1.7.0.zip

+  - 7z x gtest-1.7.0.zip

+  - rename gtest-1.7.0 gtest

+

+before_build:

+  - if %platform%==Win32 set generator=Visual Studio 12

+  - if %platform%==Win64 set generator=Visual Studio 12 Win64

+  - if %platform%==Win32 set vcplatform=Win32

+  - if %platform%==Win64 set vcplatform=x64

+

+build_script:

+  - mkdir build

+  - cd build

+  - cmake -G "%generator%" -DBUILD_SHARED_LIBS=%BUILD_DLL% ../cmake

+  - msbuild protobuf.sln /p:Platform=%vcplatform% /logger:"C:\Program Files\AppVeyor\BuildAgent\Appveyor.MSBuildLogger.dll"

+  - cd %configuration%

+  - tests.exe

+

+

diff --git a/cmake/tests.cmake b/cmake/tests.cmake
index 2489152..8fb5eef 100644
--- a/cmake/tests.cmake
+++ b/cmake/tests.cmake
@@ -25,6 +25,7 @@
   google/protobuf/unittest_drop_unknown_fields.proto
   google/protobuf/unittest_embed_optimize_for.proto
   google/protobuf/unittest_empty.proto
+  google/protobuf/unittest_enormous_descriptor.proto
   google/protobuf/unittest_import.proto
   google/protobuf/unittest_import_public.proto
   google/protobuf/unittest_lite_imports_nonlite.proto
diff --git a/config.h.include b/config.h.include
deleted file mode 100644
index 0c557fb..0000000
--- a/config.h.include
+++ /dev/null
@@ -1,7 +0,0 @@
-HASH_MAP_CLASS
-HASH_MAP_H
-HASH_NAMESPACE
-HASH_SET_CLASS
-HASH_SET_H
-HAVE_HASH_MAP
-HAVE_HASH_SET
diff --git a/src/Makefile.am b/src/Makefile.am
index 6affcbf..ac6ec6f 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -41,24 +41,12 @@
 clean-local:
 	rm -f *.loT
 
-public_config = google/protobuf/stubs/pbconfig.h
-
-CLEANFILES = $(protoc_outputs) $(public_config) unittest_proto_middleman \
+CLEANFILES = $(protoc_outputs) unittest_proto_middleman \
              testzip.jar testzip.list testzip.proto testzip.zip
 
 MAINTAINERCLEANFILES =   \
   Makefile.in
 
-# Generate and distribute a minimum config.h file to make hash_map work.
-# The autoheader config has too much info, which might conflict with other
-# macros applications might include. Thus, we create a stubs/pbconfig.h, that
-# only #defines what we really need, and prefix it with GOOGLE_PROTOBUF_ to
-# avoid conflicts.
-$(public_config): $(top_builddir)/config.h $(top_srcdir)/config.h.include
-	echo "// Note: Google Protobuf internal only. Do NOT include." > $@
-	cat $(top_builddir)/config.h | grep -f $(top_srcdir)/config.h.include | \
-	sed 's,#define , #define GOOGLE_PROTOBUF_,' >> $@
-
 nobase_include_HEADERS =                                        \
   google/protobuf/stubs/atomic_sequence_num.h                   \
   google/protobuf/stubs/atomicops.h                             \
@@ -80,6 +68,7 @@
   google/protobuf/stubs/fastmem.h                               \
   google/protobuf/stubs/hash.h                                  \
   google/protobuf/stubs/once.h                                  \
+  google/protobuf/stubs/pbconfig.h                              \
   google/protobuf/stubs/platform_macros.h                       \
   google/protobuf/stubs/shared_ptr.h                            \
   google/protobuf/stubs/singleton.h                             \
@@ -152,9 +141,6 @@
   google/protobuf/compiler/ruby/ruby_generator.h                \
   google/protobuf/compiler/csharp/csharp_generator.h
 
-nobase_nodist_include_HEADERS =                                 \
-  $(public_config)
-
 lib_LTLIBRARIES = libprotobuf-lite.la libprotobuf.la libprotoc.la
 
 libprotobuf_lite_la_LIBADD = $(PTHREAD_LIBS)
@@ -180,7 +166,6 @@
   google/protobuf/io/coded_stream_inl.h                        \
   google/protobuf/io/zero_copy_stream.cc                       \
   google/protobuf/io/zero_copy_stream_impl_lite.cc
-nodist_libprotobuf_lite_la_SOURCES = $(public_config)
 
 libprotobuf_la_LIBADD = $(PTHREAD_LIBS)
 libprotobuf_la_LDFLAGS = -version-info 10:0:0 -export-dynamic -no-undefined
@@ -412,6 +397,7 @@
   google/protobuf/unittest_drop_unknown_fields.proto           \
   google/protobuf/unittest_embed_optimize_for.proto            \
   google/protobuf/unittest_empty.proto                         \
+  google/protobuf/unittest_enormous_descriptor.proto           \
   google/protobuf/unittest_import_lite.proto                   \
   google/protobuf/unittest_import.proto                        \
   google/protobuf/unittest_import_public_lite.proto            \
@@ -453,8 +439,7 @@
   google/protobuf/compiler/ruby/ruby_generated_code.proto      \
   google/protobuf/compiler/ruby/ruby_generated_code.rb         \
   google/protobuf/compiler/package_info.h                      \
-  google/protobuf/compiler/zip_output_unittest.sh              \
-  google/protobuf/unittest_enormous_descriptor.proto
+  google/protobuf/compiler/zip_output_unittest.sh
 
 protoc_lite_outputs =                                          \
   google/protobuf/map_lite_unittest.pb.cc                      \
@@ -486,6 +471,8 @@
   google/protobuf/unittest_embed_optimize_for.pb.h             \
   google/protobuf/unittest_empty.pb.cc                         \
   google/protobuf/unittest_empty.pb.h                          \
+  google/protobuf/unittest_enormous_descriptor.pb.cc           \
+  google/protobuf/unittest_enormous_descriptor.pb.h            \
   google/protobuf/unittest_import.pb.cc                        \
   google/protobuf/unittest_import.pb.h                         \
   google/protobuf/unittest_import_public.pb.cc                 \
@@ -517,7 +504,7 @@
   google/protobuf/compiler/cpp/cpp_test_bad_identifiers.pb.cc  \
   google/protobuf/compiler/cpp/cpp_test_bad_identifiers.pb.h
 
-BUILT_SOURCES = $(public_config) $(protoc_outputs)
+BUILT_SOURCES = $(protoc_outputs)
 
 if USE_EXTERNAL_PROTOC
 
diff --git a/src/google/protobuf/compiler/cpp/cpp_file.cc b/src/google/protobuf/compiler/cpp/cpp_file.cc
index b997a51..1f0a820 100644
--- a/src/google/protobuf/compiler/cpp/cpp_file.cc
+++ b/src/google/protobuf/compiler/cpp/cpp_file.cc
@@ -434,20 +434,52 @@
     string file_data;
     file_proto.SerializeToString(&file_data);
 
-    printer->Print(
-      "::google::protobuf::DescriptorPool::InternalAddGeneratedFile(");
+    // Workaround for MSVC: "Error C1091: compiler limit: string exceeds 65535
+    // bytes in length". Declare a static array of characters rather than use a
+    // string literal.
+    if (file_data.size() > 65535) {
+      printer->Print(
+        "static const char descriptor[] = {\n");
+      printer->Indent();
 
-    // Only write 40 bytes per line.
-    static const int kBytesPerLine = 40;
-    for (int i = 0; i < file_data.size(); i += kBytesPerLine) {
-      printer->Print("\n  \"$data$\"",
-                     "data",
-                     EscapeTrigraphs(
-                         CEscape(file_data.substr(i, kBytesPerLine))));
+      // Only write 25 bytes per line.
+      static const int kBytesPerLine = 25;
+      for (int i = 0; i < file_data.size();) {
+          for (int j = 0; j < kBytesPerLine && i < file_data.size(); ++i, ++j) {
+            printer->Print(
+              "$char$, ",
+              "char", SimpleItoa(file_data[i]));
+          }
+          printer->Print(
+            "\n");
+      }
+
+      printer->Outdent();
+      printer->Print(
+        "};\n");
+
+      printer->Print(
+        "::google::protobuf::DescriptorPool::InternalAddGeneratedFile(descriptor, $size$);\n",
+        "size", SimpleItoa(file_data.size()));
+
+    } else {
+
+      printer->Print(
+        "::google::protobuf::DescriptorPool::InternalAddGeneratedFile(");
+  
+      // Only write 40 bytes per line.
+      static const int kBytesPerLine = 40;
+      for (int i = 0; i < file_data.size(); i += kBytesPerLine) {
+        printer->Print("\n  \"$data$\"",
+                       "data",
+                       EscapeTrigraphs(
+                           CEscape(file_data.substr(i, kBytesPerLine))));
+      }
+      printer->Print(
+          ", $size$);\n",
+        "size", SimpleItoa(file_data.size()));
+  
     }
-    printer->Print(
-        ", $size$);\n",
-      "size", SimpleItoa(file_data.size()));
 
     // Call MessageFactory::InternalRegisterGeneratedFile().
     printer->Print(
diff --git a/src/google/protobuf/compiler/cpp/cpp_unittest.cc b/src/google/protobuf/compiler/cpp/cpp_unittest.cc
index b11fb21..bd1c0fd 100644
--- a/src/google/protobuf/compiler/cpp/cpp_unittest.cc
+++ b/src/google/protobuf/compiler/cpp/cpp_unittest.cc
@@ -55,6 +55,7 @@
 #include <google/protobuf/unittest.pb.h>
 #include <google/protobuf/unittest_optimize_for.pb.h>
 #include <google/protobuf/unittest_embed_optimize_for.pb.h>
+#include <google/protobuf/unittest_enormous_descriptor.pb.h>
 #include <google/protobuf/unittest_no_generic_services.pb.h>
 #include <google/protobuf/test_util.h>
 #include <google/protobuf/compiler/cpp/cpp_helpers.h>
@@ -130,6 +131,17 @@
             generated_decsriptor_proto.DebugString());
 }
 
+// Test that generated code has proper descriptors:
+// Touch a descriptor generated from an enormous message to validate special
+// handling for descriptors exceeding the C++ standard's recommended minimum
+// limit for string literal size
+TEST(GeneratedDescriptorTest, EnormousDescriptor) {
+  const Descriptor* generated_descriptor =
+    TestEnormousDescriptor::descriptor();
+
+  EXPECT_TRUE(generated_descriptor != NULL);
+}
+
 #endif  // !PROTOBUF_TEST_NO_DESCRIPTORS
 
 // ===================================================================
diff --git a/src/google/protobuf/descriptor.pb.cc b/src/google/protobuf/descriptor.pb.cc
index fc13d8d..30b3a3a 100644
--- a/src/google/protobuf/descriptor.pb.cc
+++ b/src/google/protobuf/descriptor.pb.cc
@@ -753,9 +753,10 @@
     "ion\032\206\001\n\010Location\022\020\n\004path\030\001 \003(\005B\002\020\001\022\020\n\004sp"
     "an\030\002 \003(\005B\002\020\001\022\030\n\020leading_comments\030\003 \001(\t\022\031"
     "\n\021trailing_comments\030\004 \001(\t\022!\n\031leading_det"
-    "ached_comments\030\006 \003(\tBY\n\023com.google.proto"
-    "bufB\020DescriptorProtosH\001\242\002\003GPB\252\002\'Google.P"
-    "rotocolBuffers.DescriptorProtos", 4951);
+    "ached_comments\030\006 \003(\tBe\n\023com.google.proto"
+    "bufB\020DescriptorProtosH\001Z\ndescriptor\242\002\003GP"
+    "B\252\002\'Google.ProtocolBuffers.DescriptorPro"
+    "tos", 4963);
   ::google::protobuf::MessageFactory::InternalRegisterGeneratedFile(
     "google/protobuf/descriptor.proto", &protobuf_RegisterTypes);
   FileDescriptorSet::default_instance_ = new FileDescriptorSet();
diff --git a/src/google/protobuf/descriptor.proto b/src/google/protobuf/descriptor.proto
index 20a6008..13f136c 100644
--- a/src/google/protobuf/descriptor.proto
+++ b/src/google/protobuf/descriptor.proto
@@ -40,6 +40,7 @@
 syntax = "proto2";
 
 package google.protobuf;
+option go_package = "descriptor";
 option java_package = "com.google.protobuf";
 option java_outer_classname = "DescriptorProtos";
 option csharp_namespace = "Google.ProtocolBuffers.DescriptorProtos";
diff --git a/src/google/protobuf/stubs/pbconfig.h b/src/google/protobuf/stubs/pbconfig.h
new file mode 100644
index 0000000..0f21c56
--- /dev/null
+++ b/src/google/protobuf/stubs/pbconfig.h
@@ -0,0 +1,142 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc.  All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+//     * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+//     * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+//     * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#ifndef GOOGLE_PROTOBUF_STUBS_PBCONFIG_H__
+#define GOOGLE_PROTOBUF_STUBS_PBCONFIG_H__
+
+#define GOOGLE_PROTOBUF_HAVE_HASH_MAP 1
+#define GOOGLE_PROTOBUF_HAVE_HASH_SET 1
+
+// Use C++11 unordered_{map|set} if available.
+#if __cplusplus >= 201103L || defined(__GXX_EXPERIMENTAL_CXX0X)
+# define GOOGLE_PROTOBUF_HAS_CXX11_HASH
+
+// For XCode >= 4.6:  the compiler is clang with libc++.
+// For earlier XCode version: the compiler is gcc-4.2.1 with libstdc++.
+// libc++ provides <unordered_map> and friends even in non C++11 mode,
+// and it does not provide the tr1 library. Therefore the following macro
+// checks against this special case.
+// Note that we should not test the __APPLE_CC__ version number or the
+// __clang__ macro, since the new compiler can still use -stdlib=libstdc++, in
+// which case <unordered_map> is not compilable without -std=c++11
+#elif defined(__APPLE_CC__)
+# if defined(_LIBCPP_VERSION)
+#  define GOOGLE_PROTOBUF_HAS_CXX11_HASH
+# elif __GNUC__ >= 4
+#  define GOOGLE_PROTOBUF_HAS_TR1
+# else
+// Not tested for gcc < 4... These setting can compile under 4.2.1 though.
+#  define GOOGLE_PROTOBUF_HASH_NAMESPACE __gnu_cxx
+#  define GOOGLE_PROTOBUF_HASH_MAP_H <ext/hash_map>
+#  define GOOGLE_PROTOBUF_HASH_MAP_CLASS hash_map
+#  define GOOGLE_PROTOBUF_HASH_SET_H <ext/hash_set>
+#  define GOOGLE_PROTOBUF_HASH_SET_CLASS hash_set
+# endif
+
+// Version checks for gcc.
+#elif defined(__GNUC__)
+// For GCC 4.x+, use tr1::unordered_map/set; otherwise, follow the
+// instructions from:
+// https://gcc.gnu.org/onlinedocs/libstdc++/manual/backwards.html
+# if __GNUC__ >= 4
+#  define GOOGLE_PROTOBUF_HAS_TR1
+# elif __GNUC__ >= 3
+#  define GOOGLE_PROTOBUF_HASH_MAP_H <backward/hash_map>
+#  define GOOGLE_PROTOBUF_HASH_MAP_CLASS hash_map
+#  define GOOGLE_PROTOBUF_HASH_SET_H <backward/hash_set>
+#  define GOOGLE_PROTOBUF_HASH_SET_CLASS hash_set
+#  if __GNUC__ == 3 && __GNUC_MINOR__ == 0
+#   define GOOGLE_PROTOBUF_HASH_NAMESPACE std       // GCC 3.0
+#  else
+#   define GOOGLE_PROTOBUF_HASH_NAMESPACE __gnu_cxx // GCC 3.1 and later
+#  endif
+# else
+#  define GOOGLE_PROTOBUF_HASH_NAMESPACE
+#  define GOOGLE_PROTOBUF_HASH_MAP_H <hash_map>
+#  define GOOGLE_PROTOBUF_HASH_MAP_CLASS hash_map
+#  define GOOGLE_PROTOBUF_HASH_SET_H <hash_set>
+#  define GOOGLE_PROTOBUF_HASH_SET_CLASS hash_set
+# endif
+
+// Version checks for MSC.
+// Apparently Microsoft decided to move hash_map *back* to the std namespace in
+// MSVC 2010:
+// http://blogs.msdn.com/vcblog/archive/2009/05/25/stl-breaking-changes-in-visual-studio-2010-beta-1.aspx
+// And.. they are moved back to stdext in MSVC 2013 (haven't checked 2012). That
+// said, use unordered_map for MSVC 2010 and beyond is our safest bet.
+#elif defined(_MSC_VER)
+# if _MSC_VER >= 1600  // Since Visual Studio 2010
+#  define GOOGLE_PROTOBUF_HAS_CXX11_HASH
+#  define GOOGLE_PROTOBUF_HASH_COMPARE std::hash_compare
+# elif _MSC_VER >= 1500  // Since Visual Studio 2008
+#  define GOOGLE_PROTOBUF_HAS_TR1
+#  define GOOGLE_PROTOBUF_HASH_COMPARE stdext::hash_compare
+# elif _MSC_VER >= 1310
+#  define GOOGLE_PROTOBUF_HASH_NAMESPACE stdext
+#  define GOOGLE_PROTOBUF_HASH_MAP_H <hash_map>
+#  define GOOGLE_PROTOBUF_HASH_MAP_CLASS hash_map
+#  define GOOGLE_PROTOBUF_HASH_SET_H <hash_set>
+#  define GOOGLE_PROTOBUF_HASH_SET_CLASS hash_set
+#  define GOOGLE_PROTOBUF_HASH_COMPARE stdext::hash_compare
+# else
+#  define GOOGLE_PROTOBUF_HASH_NAMESPACE std
+#  define GOOGLE_PROTOBUF_HASH_MAP_H <hash_map>
+#  define GOOGLE_PROTOBUF_HASH_MAP_CLASS hash_map
+#  define GOOGLE_PROTOBUF_HASH_SET_H <hash_set>
+#  define GOOGLE_PROTOBUF_HASH_SET_CLASS hash_set
+#  define GOOGLE_PROTOBUF_HASH_COMPARE stdext::hash_compare
+# endif
+
+// **ADD NEW COMPILERS SUPPORT HERE.**
+// For other compilers, undefine the macro and fallback to use std::map, in
+// google/protobuf/stubs/hash.h
+#else
+# undef GOOGLE_PROTOBUF_HAVE_HASH_MAP
+# undef GOOGLE_PROTOBUF_HAVE_HASH_SET
+#endif
+
+#if defined(GOOGLE_PROTOBUF_HAS_CXX11_HASH)
+# define GOOGLE_PROTOBUF_HASH_NAMESPACE std
+# define GOOGLE_PROTOBUF_HASH_MAP_H <unordered_map>
+# define GOOGLE_PROTOBUF_HASH_MAP_CLASS unordered_map
+# define GOOGLE_PROTOBUF_HASH_SET_H <unordered_set>
+# define GOOGLE_PROTOBUF_HASH_SET_CLASS unordered_set
+#elif defined(GOOGLE_PROTOBUF_HAS_TR1)
+# define GOOGLE_PROTOBUF_HASH_NAMESPACE std::tr1
+# define GOOGLE_PROTOBUF_HASH_MAP_H <tr1/unordered_map>
+# define GOOGLE_PROTOBUF_HASH_MAP_CLASS unordered_map
+# define GOOGLE_PROTOBUF_HASH_SET_H <tr1/unordered_set>
+# define GOOGLE_PROTOBUF_HASH_SET_CLASS unordered_set
+#endif
+
+#undef GOOGLE_PROTOBUF_HAS_CXX11_HASH
+#undef GOOGLE_PROTOBUF_HAS_TR1
+
+#endif // GOOGLE_PROTOBUF_STUBS_PBCONFIG_H__