From 99ae0ed39723b9c8f97fbdde070681e2a8b7a20e Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Sat, 19 Nov 2011 10:22:26 -0800 Subject: Changes to get upb compiling inside Google. --- tests/test_vs_proto2.cc | 32 ++++++++++++-------------------- 1 file changed, 12 insertions(+), 20 deletions(-) (limited to 'tests/test_vs_proto2.cc') diff --git a/tests/test_vs_proto2.cc b/tests/test_vs_proto2.cc index 222bcdb..8d13f33 100644 --- a/tests/test_vs_proto2.cc +++ b/tests/test_vs_proto2.cc @@ -8,16 +8,16 @@ */ #include +#include #include #include #include +#include "benchmarks/google_messages.pb.h" #include "upb/def.h" #include "upb/msg.h" #include "upb/pb/glue.h" #include "upb_test.h" -#include MESSAGE_HFILE - size_t string_size; void compare(const google::protobuf::Message& proto2_msg, @@ -87,7 +87,6 @@ void compare_arrays(const google::protobuf::Reflection *r, ASSERT(upb_seq_done(iter)); } -#include void compare_values(const google::protobuf::Reflection *r, const google::protobuf::Message& proto2_msg, const google::protobuf::FieldDescriptor *proto2_f, @@ -200,32 +199,25 @@ void parse_and_compare(MESSAGE_CIDENT *proto2_msg, int main(int argc, char *argv[]) { - // Change cwd to where the binary is. - (void)argc; - char *lastslash = strrchr(argv[0], '/'); - char *progname = argv[0]; - if(lastslash) { - *lastslash = '\0'; - if(chdir(argv[0]) < 0) { - fprintf(stderr, "Error changing directory to %s.\n", argv[0]); - return 1; - } - *lastslash = '/'; - progname = lastslash + 3; /* "/b_" */ + if (argc < 3) { + fprintf(stderr, "Usage: test_vs_proto2 \n"); + return 1; } + const char *descriptor_file = argv[1]; + const char *message_file = argv[2]; // Initialize upb state, parse descriptor. upb_status status = UPB_STATUS_INIT; upb_symtab *symtab = upb_symtab_new(); size_t fds_len; - const char *fds = upb_readfile(MESSAGE_DESCRIPTOR_FILE, &fds_len); + const char *fds = upb_readfile(descriptor_file, &fds_len); if(fds == NULL) { - fprintf(stderr, "Couldn't read " MESSAGE_DESCRIPTOR_FILE ".\n"); + fprintf(stderr, "Couldn't read %s.\n", descriptor_file); return 1; } upb_load_descriptor_into_symtab(symtab, fds, fds_len, &status); if(!upb_ok(&status)) { - fprintf(stderr, "Error importing " MESSAGE_DESCRIPTOR_FILE ": %s", + fprintf(stderr, "Error importing %s: %s", descriptor_file, upb_status_getstr(&status)); return 1; } @@ -240,9 +232,9 @@ int main(int argc, char *argv[]) // Read the message data itself. size_t len; - const char *str = upb_readfile(MESSAGE_FILE, &len); + const char *str = upb_readfile(message_file, &len); if(str == NULL) { - fprintf(stderr, "Error reading " MESSAGE_FILE "\n"); + fprintf(stderr, "Error reading %s\n", message_file); return 1; } -- cgit v1.2.3