You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@thrift.apache.org by hc...@apache.org on 2014/11/18 11:33:56 UTC
[04/37] thrift git commit: Revert "THRIFT-2729: C++ - .clang-format
created and applied"
http://git-wip-us.apache.org/repos/asf/thrift/blob/240120c8/lib/cpp/src/thrift/windows/SocketPair.cpp
----------------------------------------------------------------------
diff --git a/lib/cpp/src/thrift/windows/SocketPair.cpp b/lib/cpp/src/thrift/windows/SocketPair.cpp
index 7228832..4b65e6b 100644
--- a/lib/cpp/src/thrift/windows/SocketPair.cpp
+++ b/lib/cpp/src/thrift/windows/SocketPair.cpp
@@ -36,65 +36,67 @@
// Win32
#include <WS2tcpip.h>
-int thrift_socketpair(int d, int type, int protocol, THRIFT_SOCKET sv[2]) {
- THRIFT_UNUSED_VARIABLE(protocol);
- THRIFT_UNUSED_VARIABLE(type);
- THRIFT_UNUSED_VARIABLE(d);
+int thrift_socketpair(int d, int type, int protocol, THRIFT_SOCKET sv[2])
+{
+ THRIFT_UNUSED_VARIABLE(protocol);
+ THRIFT_UNUSED_VARIABLE(type);
+ THRIFT_UNUSED_VARIABLE(d);
- union {
- struct sockaddr_in inaddr;
- struct sockaddr addr;
- } a;
- THRIFT_SOCKET listener;
- int e;
- socklen_t addrlen = sizeof(a.inaddr);
- DWORD flags = 0;
- int reuse = 1;
+ union {
+ struct sockaddr_in inaddr;
+ struct sockaddr addr;
+ } a;
+ THRIFT_SOCKET listener;
+ int e;
+ socklen_t addrlen = sizeof(a.inaddr);
+ DWORD flags = 0;
+ int reuse = 1;
- if (sv == 0) {
- WSASetLastError(WSAEINVAL);
- return SOCKET_ERROR;
- }
+ if (sv == 0) {
+ WSASetLastError(WSAEINVAL);
+ return SOCKET_ERROR;
+ }
- listener = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
- if (listener == INVALID_SOCKET)
- return SOCKET_ERROR;
+ listener = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
+ if (listener == INVALID_SOCKET)
+ return SOCKET_ERROR;
- memset(&a, 0, sizeof(a));
- a.inaddr.sin_family = AF_INET;
- a.inaddr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
- a.inaddr.sin_port = 0;
+ memset(&a, 0, sizeof(a));
+ a.inaddr.sin_family = AF_INET;
+ a.inaddr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
+ a.inaddr.sin_port = 0;
- sv[0] = sv[1] = INVALID_SOCKET;
- do {
- // ignore errors coming out of this setsockopt. This is because
- // SO_EXCLUSIVEADDRUSE requires admin privileges on WinXP, but we don't
- // want to force socket pairs to be an admin.
- setsockopt(listener, SOL_SOCKET, SO_EXCLUSIVEADDRUSE, (char*)&reuse, (socklen_t)sizeof(reuse));
- if (bind(listener, &a.addr, sizeof(a.inaddr)) == SOCKET_ERROR)
- break;
- if (getsockname(listener, &a.addr, &addrlen) == SOCKET_ERROR)
- break;
- if (listen(listener, 1) == SOCKET_ERROR)
- break;
- sv[0] = WSASocket(AF_INET, SOCK_STREAM, 0, NULL, 0, flags);
- if (sv[0] == INVALID_SOCKET)
- break;
- if (connect(sv[0], &a.addr, sizeof(a.inaddr)) == SOCKET_ERROR)
- break;
- sv[1] = accept(listener, NULL, NULL);
- if (sv[1] == INVALID_SOCKET)
- break;
+ sv[0] = sv[1] = INVALID_SOCKET;
+ do {
+ //ignore errors coming out of this setsockopt. This is because
+ //SO_EXCLUSIVEADDRUSE requires admin privileges on WinXP, but we don't
+ //want to force socket pairs to be an admin.
+ setsockopt(listener, SOL_SOCKET, SO_EXCLUSIVEADDRUSE,
+ (char*) &reuse, (socklen_t) sizeof(reuse));
+ if (bind(listener, &a.addr, sizeof(a.inaddr)) == SOCKET_ERROR)
+ break;
+ if (getsockname(listener, &a.addr, &addrlen) == SOCKET_ERROR)
+ break;
+ if (listen(listener, 1) == SOCKET_ERROR)
+ break;
+ sv[0] = WSASocket(AF_INET, SOCK_STREAM, 0, NULL, 0, flags);
+ if (sv[0] == INVALID_SOCKET)
+ break;
+ if (connect(sv[0], &a.addr, sizeof(a.inaddr)) == SOCKET_ERROR)
+ break;
+ sv[1] = accept(listener, NULL, NULL);
+ if (sv[1] == INVALID_SOCKET)
+ break;
- closesocket(listener);
- return 0;
+ closesocket(listener);
+ return 0;
- } while (0);
+ } while (0);
- e = WSAGetLastError();
- closesocket(listener);
- closesocket(sv[0]);
- closesocket(sv[1]);
- WSASetLastError(e);
- return SOCKET_ERROR;
+ e = WSAGetLastError();
+ closesocket(listener);
+ closesocket(sv[0]);
+ closesocket(sv[1]);
+ WSASetLastError(e);
+ return SOCKET_ERROR;
}
http://git-wip-us.apache.org/repos/asf/thrift/blob/240120c8/lib/cpp/src/thrift/windows/Sync.h
----------------------------------------------------------------------
diff --git a/lib/cpp/src/thrift/windows/Sync.h b/lib/cpp/src/thrift/windows/Sync.h
index 5d32199..ded6ea3 100644
--- a/lib/cpp/src/thrift/windows/Sync.h
+++ b/lib/cpp/src/thrift/windows/Sync.h
@@ -33,55 +33,53 @@
code, use the classes found in the concurrency namespace
*/
-namespace apache {
-namespace thrift {
+namespace apache { namespace thrift {
struct TCriticalSection : boost::noncopyable {
CRITICAL_SECTION cs;
- TCriticalSection() { InitializeCriticalSection(&cs); }
- ~TCriticalSection() { DeleteCriticalSection(&cs); }
+ TCriticalSection() {InitializeCriticalSection(&cs);}
+ ~TCriticalSection() {DeleteCriticalSection(&cs);}
};
class TAutoCrit : boost::noncopyable {
private:
- CRITICAL_SECTION* cs_;
-
+ CRITICAL_SECTION *cs_;
public:
- explicit TAutoCrit(TCriticalSection& cs) : cs_(&cs.cs) { EnterCriticalSection(cs_); }
- ~TAutoCrit() { LeaveCriticalSection(cs_); }
+ explicit TAutoCrit(TCriticalSection &cs) : cs_(&cs.cs) {EnterCriticalSection(cs_);}
+ ~TAutoCrit() {LeaveCriticalSection(cs_);}
};
struct TAutoResetEvent : boost::noncopyable {
HANDLE h;
TAutoResetEvent() {
- h = CreateEvent(NULL, FALSE, FALSE, NULL);
- if (h == NULL) {
+ h = CreateEvent( NULL, FALSE, FALSE, NULL);
+ if(h == NULL) {
GlobalOutput.perror("TAutoResetEvent unable to create event, GLE=", GetLastError());
throw apache::thrift::concurrency::SystemResourceException("CreateEvent failed");
}
}
- ~TAutoResetEvent() { CloseHandle(h); }
+ ~TAutoResetEvent() {CloseHandle(h);}
};
struct TManualResetEvent : boost::noncopyable {
HANDLE h;
TManualResetEvent() {
- h = CreateEvent(NULL, TRUE, FALSE, NULL);
- if (h == NULL) {
+ h = CreateEvent( NULL, TRUE, FALSE, NULL);
+ if(h == NULL) {
GlobalOutput.perror("TManualResetEvent unable to create event, GLE=", GetLastError());
throw apache::thrift::concurrency::SystemResourceException("CreateEvent failed");
}
}
- ~TManualResetEvent() { CloseHandle(h); }
+ ~TManualResetEvent() {CloseHandle(h);}
};
struct TAutoHandle : boost::noncopyable {
HANDLE h;
explicit TAutoHandle(HANDLE h_ = INVALID_HANDLE_VALUE) : h(h_) {}
~TAutoHandle() {
- if (h != INVALID_HANDLE_VALUE)
+ if(h != INVALID_HANDLE_VALUE)
CloseHandle(h);
}
@@ -91,14 +89,14 @@ struct TAutoHandle : boost::noncopyable {
return retval;
}
void reset(HANDLE h_ = INVALID_HANDLE_VALUE) {
- if (h_ == h)
+ if(h_ == h)
return;
- if (h != INVALID_HANDLE_VALUE)
+ if(h != INVALID_HANDLE_VALUE)
CloseHandle(h);
h = h_;
}
};
-}
-} // apache::thrift
+
+}} //apache::thrift
#endif
http://git-wip-us.apache.org/repos/asf/thrift/blob/240120c8/lib/cpp/src/thrift/windows/TWinsockSingleton.cpp
----------------------------------------------------------------------
diff --git a/lib/cpp/src/thrift/windows/TWinsockSingleton.cpp b/lib/cpp/src/thrift/windows/TWinsockSingleton.cpp
index 2e0ccf5..2e306c6 100644
--- a/lib/cpp/src/thrift/windows/TWinsockSingleton.cpp
+++ b/lib/cpp/src/thrift/windows/TWinsockSingleton.cpp
@@ -23,49 +23,51 @@
#include <boost/assert.hpp>
#include <stdexcept>
-namespace apache {
-namespace thrift {
-namespace transport {
+namespace apache { namespace thrift { namespace transport {
TWinsockSingleton::instance_ptr TWinsockSingleton::instance_ptr_(NULL);
#if USE_BOOST_THREAD
-boost::once_flag TWinsockSingleton::flags_ = BOOST_ONCE_INIT;
+boost::once_flag TWinsockSingleton::flags_ = BOOST_ONCE_INIT;
#elif USE_STD_THREAD
-std::once_flag TWinsockSingleton::flags_;
+std::once_flag TWinsockSingleton::flags_;
#else
#error For windows you must choose USE_BOOST_THREAD or USE_STD_THREAD
#endif
//------------------------------------------------------------------------------
-TWinsockSingleton::TWinsockSingleton(void) {
- WORD version(MAKEWORD(2, 2));
- WSAData data = {0};
+TWinsockSingleton::TWinsockSingleton(void)
+{
+ WORD version(MAKEWORD(2, 2));
+ WSAData data = {0};
- int error(WSAStartup(version, &data));
- if (error != 0) {
- BOOST_ASSERT(false);
- throw std::runtime_error("Failed to initialise Winsock.");
- }
+ int error(WSAStartup(version, &data));
+ if (error != 0)
+ {
+ BOOST_ASSERT(false);
+ throw std::runtime_error("Failed to initialise Winsock.");
+ }
}
//------------------------------------------------------------------------------
-TWinsockSingleton::~TWinsockSingleton(void) {
- WSACleanup();
+TWinsockSingleton::~TWinsockSingleton(void)
+{
+ WSACleanup();
}
//------------------------------------------------------------------------------
-void TWinsockSingleton::create(void) {
+void TWinsockSingleton::create(void)
+{
#if USE_BOOST_THREAD
- boost::call_once(init, flags_);
+ boost::call_once(init, flags_);
#elif USE_STD_THREAD
- std::call_once(flags_, init);
+ std::call_once(flags_, init);
#endif
}
//------------------------------------------------------------------------------
-void TWinsockSingleton::init(void) {
- instance_ptr_.reset(new TWinsockSingleton);
+void TWinsockSingleton::init(void)
+{
+ instance_ptr_.reset(new TWinsockSingleton);
}
-}
-}
-} // apache::thrift::transport
+
+}}} // apache::thrift::transport
http://git-wip-us.apache.org/repos/asf/thrift/blob/240120c8/lib/cpp/src/thrift/windows/TWinsockSingleton.h
----------------------------------------------------------------------
diff --git a/lib/cpp/src/thrift/windows/TWinsockSingleton.h b/lib/cpp/src/thrift/windows/TWinsockSingleton.h
index dc1b52f..ab12c22 100644
--- a/lib/cpp/src/thrift/windows/TWinsockSingleton.h
+++ b/lib/cpp/src/thrift/windows/TWinsockSingleton.h
@@ -42,43 +42,47 @@
#error For windows you must choose USE_BOOST_THREAD or USE_STD_THREAD
#endif
-namespace apache {
-namespace thrift {
-namespace transport {
+namespace apache { namespace thrift { namespace transport {
/**
* Winsock2 must be intialised once only in order to create sockets. This class
* performs a one time initialisation when create is called.
*/
-class TWinsockSingleton : private boost::noncopyable {
+class TWinsockSingleton : private boost::noncopyable
+{
public:
- typedef boost::scoped_ptr<TWinsockSingleton> instance_ptr;
+
+ typedef boost::scoped_ptr<TWinsockSingleton> instance_ptr;
private:
- TWinsockSingleton(void);
+
+ TWinsockSingleton(void);
public:
- ~TWinsockSingleton(void);
+
+ ~TWinsockSingleton(void);
public:
- static void create(void);
+
+ static void create(void);
private:
- static void init(void);
+
+ static void init(void);
private:
- static instance_ptr instance_ptr_;
+
+ static instance_ptr instance_ptr_;
#if USE_BOOST_THREAD
- static boost::once_flag flags_;
+ static boost::once_flag flags_;
#elif USE_STD_THREAD
- static std::once_flag flags_;
+ static std::once_flag flags_;
#else
#error Need a non-Boost non-C++11 way to track single initialization here.
#endif
};
-}
-}
-} // apache::thrift::transport
+
+}}} // apache::thrift::transport
#endif // _THRIFT_TRANSPORT_WINDOWS_TWINSOCKSINGLETON_H_
http://git-wip-us.apache.org/repos/asf/thrift/blob/240120c8/lib/cpp/src/thrift/windows/WinFcntl.cpp
----------------------------------------------------------------------
diff --git a/lib/cpp/src/thrift/windows/WinFcntl.cpp b/lib/cpp/src/thrift/windows/WinFcntl.cpp
index c8b85f3..3dd4e3d 100644
--- a/lib/cpp/src/thrift/windows/WinFcntl.cpp
+++ b/lib/cpp/src/thrift/windows/WinFcntl.cpp
@@ -19,46 +19,54 @@
#include <thrift/windows/WinFcntl.h>
-int thrift_fcntl(THRIFT_SOCKET fd, int cmd, int flags) {
- if (cmd != THRIFT_F_GETFL && cmd != THRIFT_F_SETFL) {
- return -1;
- }
+int thrift_fcntl(THRIFT_SOCKET fd, int cmd, int flags)
+{
+ if(cmd != THRIFT_F_GETFL && cmd != THRIFT_F_SETFL)
+ {
+ return -1;
+ }
- if (flags != THRIFT_O_NONBLOCK && flags != 0) {
- return -1;
- }
+ if(flags != THRIFT_O_NONBLOCK && flags != 0)
+ {
+ return -1;
+ }
- if (cmd == THRIFT_F_GETFL) {
- return 0;
- }
+ if(cmd == THRIFT_F_GETFL)
+ {
+ return 0;
+ }
- int res;
- if (flags) {
- res = ioctlsocket(fd, FIONBIO, reinterpret_cast<u_long*>(&(flags = 1)));
- } else {
- res = ioctlsocket(fd, FIONBIO, reinterpret_cast<u_long*>(&(flags = 0)));
- }
+ int res;
+ if(flags)
+ {
+ res = ioctlsocket(fd, FIONBIO, reinterpret_cast<u_long *>(&(flags = 1)));
+ }
+ else
+ {
+ res = ioctlsocket(fd, FIONBIO, reinterpret_cast<u_long *>(&(flags = 0)));
+ }
- return res;
+ return res;
}
-#if WINVER <= 0x0502 // XP, Server2003
-int thrift_poll(THRIFT_POLLFD* fdArray, ULONG nfds, INT timeout) {
+#if WINVER <= 0x0502 //XP, Server2003
+int thrift_poll(THRIFT_POLLFD *fdArray, ULONG nfds, INT timeout)
+{
fd_set read_fds, write_fds;
- fd_set* read_fds_ptr = NULL;
+ fd_set* read_fds_ptr = NULL;
fd_set* write_fds_ptr = NULL;
FD_ZERO(&read_fds);
FD_ZERO(&write_fds);
- for (ULONG i = 0; i < nfds; i++) {
- // Read (in) socket
- if ((fdArray[i].events & THRIFT_POLLIN) == THRIFT_POLLIN) {
+ for(ULONG i=0; i<nfds; i++) {
+ //Read (in) socket
+ if((fdArray[i].events & THRIFT_POLLIN) == THRIFT_POLLIN) {
read_fds_ptr = &read_fds;
FD_SET(fdArray[i].fd, &read_fds);
}
- // Write (out) socket
- else if ((fdArray[i].events & THRIFT_POLLOUT) == THRIFT_POLLOUT) {
+ //Write (out) socket
+ else if((fdArray[i].events & THRIFT_POLLOUT) == THRIFT_POLLOUT) {
write_fds_ptr = &write_fds;
FD_SET(fdArray[i].fd, &write_fds);
}
@@ -66,35 +74,37 @@ int thrift_poll(THRIFT_POLLFD* fdArray, ULONG nfds, INT timeout) {
timeval time_out;
timeval* time_out_ptr = NULL;
- if (timeout >= 0) {
+ if(timeout >= 0) {
timeval time_out = {timeout / 1000, (timeout % 1000) * 1000};
time_out_ptr = &time_out;
- } else { // to avoid compiler warnings
+ }
+ else { //to avoid compiler warnings
(void)time_out;
(void)timeout;
}
int sktready = select(1, read_fds_ptr, write_fds_ptr, NULL, time_out_ptr);
- if (sktready > 0) {
- for (ULONG i = 0; i < nfds; i++) {
+ if(sktready > 0) {
+ for(ULONG i=0; i<nfds; i++) {
fdArray[i].revents = 0;
- if (FD_ISSET(fdArray[i].fd, &read_fds))
+ if(FD_ISSET(fdArray[i].fd, &read_fds))
fdArray[i].revents |= THRIFT_POLLIN;
- if (FD_ISSET(fdArray[i].fd, &write_fds))
+ if(FD_ISSET(fdArray[i].fd, &write_fds))
fdArray[i].revents |= THRIFT_POLLOUT;
}
}
return sktready;
}
-#else // Vista, Win7...
-int thrift_poll(THRIFT_POLLFD* fdArray, ULONG nfds, INT timeout) {
+#else //Vista, Win7...
+int thrift_poll(THRIFT_POLLFD *fdArray, ULONG nfds, INT timeout)
+{
return WSAPoll(fdArray, nfds, timeout);
}
#endif // WINVER
#ifdef _WIN32_WCE
std::string thrift_wstr2str(std::wstring ws) {
- std::string s(ws.begin(), ws.end());
- return s;
+ std::string s(ws.begin(), ws.end());
+ return s;
}
#endif
http://git-wip-us.apache.org/repos/asf/thrift/blob/240120c8/lib/cpp/src/thrift/windows/WinFcntl.h
----------------------------------------------------------------------
diff --git a/lib/cpp/src/thrift/windows/WinFcntl.h b/lib/cpp/src/thrift/windows/WinFcntl.h
index 6c6be97..118c9a4 100644
--- a/lib/cpp/src/thrift/windows/WinFcntl.h
+++ b/lib/cpp/src/thrift/windows/WinFcntl.h
@@ -36,17 +36,17 @@
#include <Winsock2.h>
#include <thrift/transport/PlatformSocket.h>
-#if WINVER <= 0x0502 // XP, Server2003
+#if WINVER <= 0x0502 //XP, Server2003
struct thrift_pollfd {
- THRIFT_SOCKET fd;
- SHORT events;
- SHORT revents;
+ THRIFT_SOCKET fd;
+ SHORT events;
+ SHORT revents;
};
#endif
extern "C" {
int thrift_fcntl(THRIFT_SOCKET fd, int cmd, int flags);
-int thrift_poll(THRIFT_POLLFD* fdArray, ULONG nfds, INT timeout);
+int thrift_poll(THRIFT_POLLFD *fdArray, ULONG nfds, INT timeout);
}
#ifdef _WIN32_WCE
http://git-wip-us.apache.org/repos/asf/thrift/blob/240120c8/lib/cpp/src/thrift/windows/config.h
----------------------------------------------------------------------
diff --git a/lib/cpp/src/thrift/windows/config.h b/lib/cpp/src/thrift/windows/config.h
index dd0da35..9261ca8 100644
--- a/lib/cpp/src/thrift/windows/config.h
+++ b/lib/cpp/src/thrift/windows/config.h
@@ -30,53 +30,53 @@
// use std::thread in MSVC11 (2012) or newer
#if _MSC_VER >= 1700
-#define USE_STD_THREAD 1
+# define USE_STD_THREAD 1
// otherwise use boost threads
#else
-#define USE_BOOST_THREAD 1
+# define USE_BOOST_THREAD 1
#endif
#ifndef TARGET_WIN_XP
-#define TARGET_WIN_XP 1
+# define TARGET_WIN_XP 1
#endif
#if TARGET_WIN_XP
-#ifndef WINVER
-#define WINVER 0x0501
-#endif
-#ifndef _WIN32_WINNT
-#define _WIN32_WINNT 0x0501
-#endif
+# ifndef WINVER
+# define WINVER 0x0501
+# endif
+# ifndef _WIN32_WINNT
+# define _WIN32_WINNT 0x0501
+# endif
#endif
#ifndef _WIN32_WINNT
-#define _WIN32_WINNT 0x0601
+# define _WIN32_WINNT 0x0601
#endif
#if defined(_M_IX86) || defined(_M_X64)
-#define ARITHMETIC_RIGHT_SHIFT 1
-#define SIGNED_RIGHT_SHIFT_IS 1
+# define ARITHMETIC_RIGHT_SHIFT 1
+# define SIGNED_RIGHT_SHIFT_IS 1
#endif
-#pragma warning(disable : 4996) // Deprecated posix name.
+#pragma warning(disable: 4996) // Deprecated posix name.
#define VERSION "1.0.0-dev"
#define HAVE_GETTIMEOFDAY 1
#define HAVE_SYS_STAT_H 1
#ifdef HAVE_STDINT_H
-#include <stdint.h>
+# include <stdint.h>
#else
-#include <boost/cstdint.hpp>
+# include <boost/cstdint.hpp>
-typedef boost::int64_t int64_t;
-typedef boost::uint64_t uint64_t;
-typedef boost::int32_t int32_t;
-typedef boost::uint32_t uint32_t;
-typedef boost::int16_t int16_t;
-typedef boost::uint16_t uint16_t;
-typedef boost::int8_t int8_t;
-typedef boost::uint8_t uint8_t;
+typedef boost::int64_t int64_t;
+typedef boost::uint64_t uint64_t;
+typedef boost::int32_t int32_t;
+typedef boost::uint32_t uint32_t;
+typedef boost::int16_t int16_t;
+typedef boost::uint16_t uint16_t;
+typedef boost::int8_t int8_t;
+typedef boost::uint8_t uint8_t;
#endif
#include <thrift/transport/PlatformSocket.h>
@@ -93,6 +93,6 @@ typedef boost::uint8_t uint8_t;
#pragma comment(lib, "Ws2.lib")
#else
#pragma comment(lib, "Ws2_32.lib")
-#pragma comment(lib, "advapi32.lib") // For security APIs in TPipeServer
+#pragma comment(lib, "advapi32.lib") //For security APIs in TPipeServer
#endif
#endif // _THRIFT_WINDOWS_CONFIG_H_
http://git-wip-us.apache.org/repos/asf/thrift/blob/240120c8/lib/cpp/test/AllProtocolTests.cpp
----------------------------------------------------------------------
diff --git a/lib/cpp/test/AllProtocolTests.cpp b/lib/cpp/test/AllProtocolTests.cpp
index 29ba193..65d1927 100644
--- a/lib/cpp/test/AllProtocolTests.cpp
+++ b/lib/cpp/test/AllProtocolTests.cpp
@@ -31,8 +31,8 @@ using namespace apache::thrift::transport;
char errorMessage[ERR_LEN];
int main(int argc, char** argv) {
- (void)argc;
- (void)argv;
+ (void) argc;
+ (void) argv;
try {
testProtocol<TBinaryProtocol>("TBinaryProtocol");
testProtocol<TCompactProtocol>("TCompactProtocol");
http://git-wip-us.apache.org/repos/asf/thrift/blob/240120c8/lib/cpp/test/AllProtocolTests.tcc
----------------------------------------------------------------------
diff --git a/lib/cpp/test/AllProtocolTests.tcc b/lib/cpp/test/AllProtocolTests.tcc
index 8c8eaa8..3c98943 100644
--- a/lib/cpp/test/AllProtocolTests.tcc
+++ b/lib/cpp/test/AllProtocolTests.tcc
@@ -45,10 +45,7 @@ void testNaked(Val val) {
Val out;
GenericIO::read(protocol, out);
if (out != val) {
- THRIFT_SNPRINTF(errorMessage,
- ERR_LEN,
- "Invalid naked test (type: %s)",
- ClassNames::getName<Val>());
+ THRIFT_SNPRINTF(errorMessage, ERR_LEN, "Invalid naked test (type: %s)", ClassNames::getName<Val>());
throw TException(errorMessage);
}
}
@@ -100,18 +97,22 @@ void testMessage() {
const char* name;
TMessageType type;
int32_t seqid;
- } messages[] = {{"short message name", T_CALL, 0},
- {"1", T_REPLY, 12345},
- {"loooooooooooooooooooooooooooooooooong", T_EXCEPTION, 1 << 16},
- {"one way push", T_ONEWAY, 12},
- {"Janky", T_CALL, 0}};
+ } messages[] = {
+ {"short message name", T_CALL, 0},
+ {"1", T_REPLY, 12345},
+ {"loooooooooooooooooooooooooooooooooong", T_EXCEPTION, 1 << 16},
+ {"one way push", T_ONEWAY, 12},
+ {"Janky", T_CALL, 0}
+ };
const int messages_count = sizeof(messages) / sizeof(TMessage);
for (int i = 0; i < messages_count; i++) {
shared_ptr<TTransport> transport(new TMemoryBuffer());
shared_ptr<TProtocol> protocol(new TProto(transport));
- protocol->writeMessageBegin(messages[i].name, messages[i].type, messages[i].seqid);
+ protocol->writeMessageBegin(messages[i].name,
+ messages[i].type,
+ messages[i].seqid);
protocol->writeMessageEnd();
std::string name;
@@ -119,7 +120,9 @@ void testMessage() {
int32_t seqid;
protocol->readMessageBegin(name, type, seqid);
- if (name != messages[i].name || type != messages[i].type || seqid != messages[i].seqid) {
+ if (name != messages[i].name ||
+ type != messages[i].type ||
+ seqid != messages[i].seqid) {
throw TException("readMessageBegin failed.");
}
}
@@ -188,6 +191,7 @@ void testProtocol(const char* protoname) {
testNaked<TProto, int64_t>((std::numeric_limits<int64_t>::min)());
testNaked<TProto, int64_t>((std::numeric_limits<int64_t>::max)());
+
testNaked<TProto, int64_t>(0);
for (int64_t i = 0; i < 62; i++) {
testNaked<TProto, int64_t>(1L << i);
@@ -206,7 +210,7 @@ void testProtocol(const char* protoname) {
testNaked<TProto, std::string>("short");
testNaked<TProto, std::string>("borderlinetiny");
testNaked<TProto, std::string>("a bit longer than the smallest possible");
- testNaked<TProto, std::string>("\x1\x2\x3\x4\x5\x6\x7\x8\x9\xA"); // kinda binary test
+ testNaked<TProto, std::string>("\x1\x2\x3\x4\x5\x6\x7\x8\x9\xA"); //kinda binary test
testField<TProto, T_STRING, std::string>("");
testField<TProto, T_STRING, std::string>("short");
http://git-wip-us.apache.org/repos/asf/thrift/blob/240120c8/lib/cpp/test/Base64Test.cpp
----------------------------------------------------------------------
diff --git a/lib/cpp/test/Base64Test.cpp b/lib/cpp/test/Base64Test.cpp
index e9e86dd..5caaae8 100644
--- a/lib/cpp/test/Base64Test.cpp
+++ b/lib/cpp/test/Base64Test.cpp
@@ -23,7 +23,7 @@
using apache::thrift::protocol::base64_encode;
using apache::thrift::protocol::base64_decode;
-BOOST_AUTO_TEST_SUITE(Base64Test)
+BOOST_AUTO_TEST_SUITE( Base64Test )
void setupTestData(int i, uint8_t* data, int& len) {
len = 0;
@@ -42,7 +42,7 @@ void checkEncoding(uint8_t* data, int len) {
}
}
-BOOST_AUTO_TEST_CASE(test_Base64_Encode_Decode) {
+BOOST_AUTO_TEST_CASE( test_Base64_Encode_Decode ) {
int len;
uint8_t testInput[3];
uint8_t testOutput[4];
@@ -64,6 +64,7 @@ BOOST_AUTO_TEST_CASE(test_Base64_Encode_Decode) {
// decode output and check that it matches input
base64_decode(testOutput, len + 1);
BOOST_ASSERT(0 == memcmp(testInput, testOutput, len));
+
}
}
http://git-wip-us.apache.org/repos/asf/thrift/blob/240120c8/lib/cpp/test/Benchmark.cpp
----------------------------------------------------------------------
diff --git a/lib/cpp/test/Benchmark.cpp b/lib/cpp/test/Benchmark.cpp
index cf6b79a..3571150 100644
--- a/lib/cpp/test/Benchmark.cpp
+++ b/lib/cpp/test/Benchmark.cpp
@@ -34,8 +34,12 @@ class Timer {
public:
timeval vStart;
- Timer() { THRIFT_GETTIMEOFDAY(&vStart, 0); }
- void start() { THRIFT_GETTIMEOFDAY(&vStart, 0); }
+ Timer() {
+ THRIFT_GETTIMEOFDAY(&vStart, 0);
+ }
+ void start() {
+ THRIFT_GETTIMEOFDAY(&vStart, 0);
+ }
double frame() {
timeval vEnd;
@@ -44,6 +48,7 @@ public:
double dend = vEnd.tv_sec + ((double)vEnd.tv_usec / 1000000.0);
return dend - dstart;
}
+
};
int main() {
@@ -54,15 +59,15 @@ int main() {
using namespace boost;
OneOfEach ooe;
- ooe.im_true = true;
- ooe.im_false = false;
- ooe.a_bite = 0x7f;
+ ooe.im_true = true;
+ ooe.im_false = false;
+ ooe.a_bite = 0x7f;
ooe.integer16 = 27000;
- ooe.integer32 = 1 << 24;
+ ooe.integer32 = 1<<24;
ooe.integer64 = (uint64_t)6000 * 1000 * 1000;
ooe.double_precision = M_PI;
- ooe.some_characters = "JSON THIS! \"\1";
- ooe.zomg_unicode = "\xd7\n\a\t";
+ ooe.some_characters = "JSON THIS! \"\1";
+ ooe.zomg_unicode = "\xd7\n\a\t";
ooe.base64 = "\1\2\3\255";
boost::shared_ptr<TMemoryBuffer> buf(new TMemoryBuffer());
@@ -72,7 +77,7 @@ int main() {
{
Timer timer;
- for (int i = 0; i < num; i++) {
+ for (int i = 0; i < num; i ++) {
buf->resetBuffer();
TBinaryProtocolT<TBufferBase> prot(buf);
ooe.write(&prot);
@@ -89,17 +94,18 @@ int main() {
Timer timer;
- for (int i = 0; i < num; i++) {
+ for (int i = 0; i < num; i ++) {
OneOfEach ooe2;
boost::shared_ptr<TMemoryBuffer> buf2(new TMemoryBuffer(data, datasize));
- // buf2->resetBuffer(data, datasize);
+ //buf2->resetBuffer(data, datasize);
TBinaryProtocolT<TBufferBase> prot(buf2);
ooe2.read(&prot);
- // cout << apache::thrift::ThriftDebugString(ooe2) << endl << endl;
+ //cout << apache::thrift::ThriftDebugString(ooe2) << endl << endl;
}
cout << " Read: " << num / (1000 * timer.frame()) << " kHz" << endl;
}
+
return 0;
}
http://git-wip-us.apache.org/repos/asf/thrift/blob/240120c8/lib/cpp/test/DebugProtoTest.cpp
----------------------------------------------------------------------
diff --git a/lib/cpp/test/DebugProtoTest.cpp b/lib/cpp/test/DebugProtoTest.cpp
index 98c66b8..5649e18 100644
--- a/lib/cpp/test/DebugProtoTest.cpp
+++ b/lib/cpp/test/DebugProtoTest.cpp
@@ -28,34 +28,37 @@ int main() {
using std::endl;
using namespace thrift::test::debug;
+
OneOfEach ooe;
- ooe.im_true = true;
- ooe.im_false = false;
- ooe.a_bite = 0x7f;
+ ooe.im_true = true;
+ ooe.im_false = false;
+ ooe.a_bite = 0x7f;
ooe.integer16 = 27000;
- ooe.integer32 = 1 << 24;
+ ooe.integer32 = 1<<24;
ooe.integer64 = (uint64_t)6000 * 1000 * 1000;
ooe.double_precision = M_PI;
- ooe.some_characters = "Debug THIS!";
- ooe.zomg_unicode = "\xd7\n\a\t";
+ ooe.some_characters = "Debug THIS!";
+ ooe.zomg_unicode = "\xd7\n\a\t";
cout << apache::thrift::ThriftDebugString(ooe) << endl << endl;
+
Nesting n;
n.my_ooe = ooe;
n.my_ooe.integer16 = 16;
n.my_ooe.integer32 = 32;
n.my_ooe.integer64 = 64;
- n.my_ooe.double_precision = (std::sqrt(5.0) + 1) / 2;
- n.my_ooe.some_characters = ":R (me going \"rrrr\")";
+ n.my_ooe.double_precision = (std::sqrt(5.0)+1)/2;
+ n.my_ooe.some_characters = ":R (me going \"rrrr\")";
n.my_ooe.zomg_unicode = "\xd3\x80\xe2\x85\xae\xce\x9d\x20"
"\xd0\x9d\xce\xbf\xe2\x85\xbf\xd0\xbe\xc9\xa1\xd0\xb3\xd0\xb0\xcf\x81\xe2\x84\x8e"
"\x20\xce\x91\x74\x74\xce\xb1\xe2\x85\xbd\xce\xba\xc7\x83\xe2\x80\xbc";
- n.my_bonk.type = 31337;
+ n.my_bonk.type = 31337;
n.my_bonk.message = "I am a bonk... xor!";
cout << apache::thrift::ThriftDebugString(n) << endl << endl;
+
HolyMoley hm;
hm.big.push_back(ooe);
@@ -77,26 +80,27 @@ int main() {
std::vector<Bonk> stage2;
hm.bonks["nothing"] = stage2;
- stage2.resize(stage2.size() + 1);
+ stage2.resize(stage2.size()+1);
stage2.back().type = 1;
stage2.back().message = "Wait.";
- stage2.resize(stage2.size() + 1);
+ stage2.resize(stage2.size()+1);
stage2.back().type = 2;
stage2.back().message = "What?";
hm.bonks["something"] = stage2;
stage2.clear();
- stage2.resize(stage2.size() + 1);
+ stage2.resize(stage2.size()+1);
stage2.back().type = 3;
stage2.back().message = "quoth";
- stage2.resize(stage2.size() + 1);
+ stage2.resize(stage2.size()+1);
stage2.back().type = 4;
stage2.back().message = "the raven";
- stage2.resize(stage2.size() + 1);
+ stage2.resize(stage2.size()+1);
stage2.back().type = 5;
stage2.back().message = "nevermore";
hm.bonks["poe"] = stage2;
cout << apache::thrift::ThriftDebugString(hm) << endl << endl;
+
return 0;
}
http://git-wip-us.apache.org/repos/asf/thrift/blob/240120c8/lib/cpp/test/DebugProtoTest_extras.cpp
----------------------------------------------------------------------
diff --git a/lib/cpp/test/DebugProtoTest_extras.cpp b/lib/cpp/test/DebugProtoTest_extras.cpp
index 5c4fd35..c89db74 100644
--- a/lib/cpp/test/DebugProtoTest_extras.cpp
+++ b/lib/cpp/test/DebugProtoTest_extras.cpp
@@ -21,15 +21,13 @@
#include "gen-cpp/DebugProtoTest_types.h"
-namespace thrift {
-namespace test {
-namespace debug {
+
+namespace thrift { namespace test { namespace debug {
bool Empty::operator<(Empty const& other) const {
- (void)other;
+ (void) other;
// It is empty, so all are equal.
return false;
}
-}
-}
-}
+
+}}}
http://git-wip-us.apache.org/repos/asf/thrift/blob/240120c8/lib/cpp/test/DenseProtoTest.cpp
----------------------------------------------------------------------
diff --git a/lib/cpp/test/DenseProtoTest.cpp b/lib/cpp/test/DenseProtoTest.cpp
index d827d3c..f73579f 100644
--- a/lib/cpp/test/DenseProtoTest.cpp
+++ b/lib/cpp/test/DenseProtoTest.cpp
@@ -42,6 +42,7 @@ g++ -Wall -g -I../lib/cpp/src -I/usr/local/include/boost-1_33_1 \
#include <thrift/protocol/TDenseProtocol.h>
#include <thrift/transport/TBufferTransports.h>
+
// Can't use memcmp here. GCC is too smart.
bool my_memeq(const char* str1, const char* str2, int len) {
for (int i = 0; i < len; i++) {
@@ -52,6 +53,7 @@ bool my_memeq(const char* str1, const char* str2, int len) {
return true;
}
+
int main() {
using std::string;
using std::cout;
@@ -61,33 +63,36 @@ int main() {
using namespace apache::thrift::transport;
using namespace apache::thrift::protocol;
+
OneOfEach ooe;
- ooe.im_true = true;
- ooe.im_false = false;
- ooe.a_bite = 0xd6;
+ ooe.im_true = true;
+ ooe.im_false = false;
+ ooe.a_bite = 0xd6;
ooe.integer16 = 27000;
- ooe.integer32 = 1 << 24;
+ ooe.integer32 = 1<<24;
ooe.integer64 = (uint64_t)6000 * 1000 * 1000;
ooe.double_precision = M_PI;
- ooe.some_characters = "Debug THIS!";
- ooe.zomg_unicode = "\xd7\n\a\t";
+ ooe.some_characters = "Debug THIS!";
+ ooe.zomg_unicode = "\xd7\n\a\t";
+
+ //cout << apache::thrift::ThriftDebugString(ooe) << endl << endl;
- // cout << apache::thrift::ThriftDebugString(ooe) << endl << endl;
Nesting n;
n.my_ooe = ooe;
n.my_ooe.integer16 = 16;
n.my_ooe.integer32 = 32;
n.my_ooe.integer64 = 64;
- n.my_ooe.double_precision = (std::sqrt(5) + 1) / 2;
- n.my_ooe.some_characters = ":R (me going \"rrrr\")";
+ n.my_ooe.double_precision = (std::sqrt(5)+1)/2;
+ n.my_ooe.some_characters = ":R (me going \"rrrr\")";
n.my_ooe.zomg_unicode = "\xd3\x80\xe2\x85\xae\xce\x9d\x20"
"\xd0\x9d\xce\xbf\xe2\x85\xbf\xd0\xbe\xc9\xa1\xd0\xb3\xd0\xb0\xcf\x81\xe2\x84\x8e"
"\x20\xce\x91\x74\x74\xce\xb1\xe2\x85\xbd\xce\xba\xc7\x83\xe2\x80\xbc";
- n.my_bonk.type = 31337;
+ n.my_bonk.type = 31337;
n.my_bonk.message = "I am a bonk... xor!";
- // cout << apache::thrift::ThriftDebugString(n) << endl << endl;
+ //cout << apache::thrift::ThriftDebugString(n) << endl << endl;
+
HolyMoley hm;
@@ -110,26 +115,26 @@ int main() {
std::vector<Bonk> stage2;
hm.bonks["nothing"] = stage2;
- stage2.resize(stage2.size() + 1);
+ stage2.resize(stage2.size()+1);
stage2.back().type = 1;
stage2.back().message = "Wait.";
- stage2.resize(stage2.size() + 1);
+ stage2.resize(stage2.size()+1);
stage2.back().type = 2;
stage2.back().message = "What?";
hm.bonks["something"] = stage2;
stage2.clear();
- stage2.resize(stage2.size() + 1);
+ stage2.resize(stage2.size()+1);
stage2.back().type = 3;
stage2.back().message = "quoth";
- stage2.resize(stage2.size() + 1);
+ stage2.resize(stage2.size()+1);
stage2.back().type = 4;
stage2.back().message = "the raven";
- stage2.resize(stage2.size() + 1);
+ stage2.resize(stage2.size()+1);
stage2.back().type = 5;
stage2.back().message = "nevermore";
hm.bonks["poe"] = stage2;
- // cout << apache::thrift::ThriftDebugString(hm) << endl << endl;
+ //cout << apache::thrift::ThriftDebugString(hm) << endl << endl;
shared_ptr<TMemoryBuffer> buffer(new TMemoryBuffer());
shared_ptr<TDenseProtocol> proto(new TDenseProtocol(buffer));
@@ -141,16 +146,16 @@ int main() {
assert(hm == hm2);
+
// Let's test out the variable-length ints, shall we?
uint64_t vlq;
-#define checkout(i, c) \
- { \
- buffer->resetBuffer(); \
- proto->vlqWrite(i); \
- proto->getTransport()->flush(); \
- assert(my_memeq(buffer->getBufferAsString().data(), c, sizeof(c) - 1)); \
- proto->vlqRead(vlq); \
- assert(vlq == i); \
+ #define checkout(i, c) { \
+ buffer->resetBuffer(); \
+ proto->vlqWrite(i); \
+ proto->getTransport()->flush(); \
+ assert(my_memeq(buffer->getBufferAsString().data(), c, sizeof(c)-1)); \
+ proto->vlqRead(vlq); \
+ assert(vlq == i); \
}
checkout(0x00000000, "\x00");
@@ -287,6 +292,7 @@ int main() {
assert(mo1 == mo6);
+
// Test fingerprint checking stuff.
{
@@ -360,7 +366,7 @@ int main() {
buffer->resetBuffer();
// Make sure the fingerprint prefix is right.
buffer->write(Nesting::binary_fingerprint, 4);
- for (int j = 0; j < 1024 * 1024; j++) {
+ for (int j = 0; j < 1024*1024; j++) {
uint8_t r = std::rand();
buffer->write(&r, 1);
}
http://git-wip-us.apache.org/repos/asf/thrift/blob/240120c8/lib/cpp/test/EnumTest.cpp
----------------------------------------------------------------------
diff --git a/lib/cpp/test/EnumTest.cpp b/lib/cpp/test/EnumTest.cpp
index 0e34b16..72f98bb 100644
--- a/lib/cpp/test/EnumTest.cpp
+++ b/lib/cpp/test/EnumTest.cpp
@@ -20,9 +20,9 @@
#include <boost/test/unit_test.hpp>
#include "gen-cpp/EnumTest_types.h"
-BOOST_AUTO_TEST_SUITE(EnumTest)
+BOOST_AUTO_TEST_SUITE( EnumTest )
-BOOST_AUTO_TEST_CASE(test_enum) {
+BOOST_AUTO_TEST_CASE( test_enum ) {
// Check that all the enum values match what we expect
BOOST_CHECK_EQUAL(MyEnum1::ME1_0, 0);
BOOST_CHECK_EQUAL(MyEnum1::ME1_1, 1);
@@ -49,7 +49,7 @@ BOOST_AUTO_TEST_CASE(test_enum) {
BOOST_CHECK_EQUAL(MyEnum4::ME4_C, 0x7fffffff);
}
-BOOST_AUTO_TEST_CASE(test_enum_constant) {
+BOOST_AUTO_TEST_CASE( test_enum_constant ) {
MyStruct ms;
BOOST_CHECK_EQUAL(ms.me2_2, 2);
BOOST_CHECK_EQUAL(ms.me3_n2, -2);
http://git-wip-us.apache.org/repos/asf/thrift/blob/240120c8/lib/cpp/test/GenericHelpers.h
----------------------------------------------------------------------
diff --git a/lib/cpp/test/GenericHelpers.h b/lib/cpp/test/GenericHelpers.h
index c175561..1853a37 100644
--- a/lib/cpp/test/GenericHelpers.h
+++ b/lib/cpp/test/GenericHelpers.h
@@ -29,41 +29,22 @@ using namespace apache::thrift::protocol;
/* ClassName Helper for cleaner exceptions */
class ClassNames {
-public:
+ public:
template <typename T>
- static const char* getName() {
- return "Unknown type";
- }
+ static const char* getName() { return "Unknown type"; }
};
-template <>
-const char* ClassNames::getName<int8_t>() {
- return "byte";
-}
-template <>
-const char* ClassNames::getName<int16_t>() {
- return "short";
-}
-template <>
-const char* ClassNames::getName<int32_t>() {
- return "int";
-}
-template <>
-const char* ClassNames::getName<int64_t>() {
- return "long";
-}
-template <>
-const char* ClassNames::getName<double>() {
- return "double";
-}
-template <>
-const char* ClassNames::getName<std::string>() {
- return "string";
-}
+template <> const char* ClassNames::getName<int8_t>() { return "byte"; }
+template <> const char* ClassNames::getName<int16_t>() { return "short"; }
+template <> const char* ClassNames::getName<int32_t>() { return "int"; }
+template <> const char* ClassNames::getName<int64_t>() { return "long"; }
+template <> const char* ClassNames::getName<double>() { return "double"; }
+template <> const char* ClassNames::getName<std::string>() { return "string"; }
/* Generic Protocol I/O function for tests */
class GenericIO {
-public:
+ public:
+
/* Write functions */
static uint32_t write(shared_ptr<TProtocol> proto, const int8_t& val) {
@@ -92,19 +73,30 @@ public:
/* Read functions */
- static uint32_t read(shared_ptr<TProtocol> proto, int8_t& val) { return proto->readByte(val); }
+ static uint32_t read(shared_ptr<TProtocol> proto, int8_t& val) {
+ return proto->readByte(val);
+ }
- static uint32_t read(shared_ptr<TProtocol> proto, int16_t& val) { return proto->readI16(val); }
+ static uint32_t read(shared_ptr<TProtocol> proto, int16_t& val) {
+ return proto->readI16(val);
+ }
- static uint32_t read(shared_ptr<TProtocol> proto, int32_t& val) { return proto->readI32(val); }
+ static uint32_t read(shared_ptr<TProtocol> proto, int32_t& val) {
+ return proto->readI32(val);
+ }
- static uint32_t read(shared_ptr<TProtocol> proto, int64_t& val) { return proto->readI64(val); }
+ static uint32_t read(shared_ptr<TProtocol> proto, int64_t& val) {
+ return proto->readI64(val);
+ }
- static uint32_t read(shared_ptr<TProtocol> proto, double& val) { return proto->readDouble(val); }
+ static uint32_t read(shared_ptr<TProtocol> proto, double& val) {
+ return proto->readDouble(val);
+ }
static uint32_t read(shared_ptr<TProtocol> proto, std::string& val) {
return proto->readString(val);
}
+
};
#endif
http://git-wip-us.apache.org/repos/asf/thrift/blob/240120c8/lib/cpp/test/JSONProtoTest.cpp
----------------------------------------------------------------------
diff --git a/lib/cpp/test/JSONProtoTest.cpp b/lib/cpp/test/JSONProtoTest.cpp
index aa07f93..a3259c0 100644
--- a/lib/cpp/test/JSONProtoTest.cpp
+++ b/lib/cpp/test/JSONProtoTest.cpp
@@ -32,33 +32,35 @@ int main() {
using apache::thrift::protocol::TJSONProtocol;
OneOfEach ooe;
- ooe.im_true = true;
- ooe.im_false = false;
- ooe.a_bite = 0x7f;
+ ooe.im_true = true;
+ ooe.im_false = false;
+ ooe.a_bite = 0x7f;
ooe.integer16 = 27000;
- ooe.integer32 = 1 << 24;
+ ooe.integer32 = 1<<24;
ooe.integer64 = (uint64_t)6000 * 1000 * 1000;
ooe.double_precision = M_PI;
- ooe.some_characters = "JSON THIS! \"\1";
- ooe.zomg_unicode = "\xd7\n\a\t";
+ ooe.some_characters = "JSON THIS! \"\1";
+ ooe.zomg_unicode = "\xd7\n\a\t";
ooe.base64 = "\1\2\3\255";
cout << apache::thrift::ThriftJSONString(ooe) << endl << endl;
+
Nesting n;
n.my_ooe = ooe;
n.my_ooe.integer16 = 16;
n.my_ooe.integer32 = 32;
n.my_ooe.integer64 = 64;
- n.my_ooe.double_precision = (std::sqrt(5.0) + 1) / 2;
- n.my_ooe.some_characters = ":R (me going \"rrrr\")";
+ n.my_ooe.double_precision = (std::sqrt(5.0)+1)/2;
+ n.my_ooe.some_characters = ":R (me going \"rrrr\")";
n.my_ooe.zomg_unicode = "\xd3\x80\xe2\x85\xae\xce\x9d\x20"
"\xd0\x9d\xce\xbf\xe2\x85\xbf\xd0\xbe\xc9\xa1\xd0\xb3\xd0\xb0\xcf\x81\xe2\x84\x8e"
"\x20\xce\x91\x74\x74\xce\xb1\xe2\x85\xbd\xce\xba\xc7\x83\xe2\x80\xbc";
- n.my_bonk.type = 31337;
+ n.my_bonk.type = 31337;
n.my_bonk.message = "I am a bonk... xor!";
cout << apache::thrift::ThriftJSONString(n) << endl << endl;
+
HolyMoley hm;
hm.big.push_back(ooe);
@@ -80,21 +82,21 @@ int main() {
std::vector<Bonk> stage2;
hm.bonks["nothing"] = stage2;
- stage2.resize(stage2.size() + 1);
+ stage2.resize(stage2.size()+1);
stage2.back().type = 1;
stage2.back().message = "Wait.";
- stage2.resize(stage2.size() + 1);
+ stage2.resize(stage2.size()+1);
stage2.back().type = 2;
stage2.back().message = "What?";
hm.bonks["something"] = stage2;
stage2.clear();
- stage2.resize(stage2.size() + 1);
+ stage2.resize(stage2.size()+1);
stage2.back().type = 3;
stage2.back().message = "quoth";
- stage2.resize(stage2.size() + 1);
+ stage2.resize(stage2.size()+1);
stage2.back().type = 4;
stage2.back().message = "the raven";
- stage2.resize(stage2.size() + 1);
+ stage2.resize(stage2.size()+1);
stage2.back().type = 5;
stage2.back().message = "nevermore";
hm.bonks["poe"] = stage2;
@@ -104,6 +106,7 @@ int main() {
boost::shared_ptr<TMemoryBuffer> buffer(new TMemoryBuffer());
boost::shared_ptr<TJSONProtocol> proto(new TJSONProtocol(buffer));
+
cout << "Testing ooe" << endl;
ooe.write(proto.get());
@@ -112,6 +115,7 @@ int main() {
assert(ooe == ooe2);
+
cout << "Testing hm" << endl;
hm.write(proto.get());
@@ -125,10 +129,10 @@ int main() {
assert(hm != hm2);
Doubles dub;
- dub.nan = HUGE_VAL / HUGE_VAL;
+ dub.nan = HUGE_VAL/HUGE_VAL;
dub.inf = HUGE_VAL;
dub.neginf = -HUGE_VAL;
- dub.repeating = 10.0 / 3.0;
+ dub.repeating = 10.0/3.0;
dub.big = 1E+305;
dub.tiny = 1E-305;
dub.zero = 0.0;
http://git-wip-us.apache.org/repos/asf/thrift/blob/240120c8/lib/cpp/test/OpenSSLManualInitTest.cpp
----------------------------------------------------------------------
diff --git a/lib/cpp/test/OpenSSLManualInitTest.cpp b/lib/cpp/test/OpenSSLManualInitTest.cpp
index b04ed43..fbecbc3 100644
--- a/lib/cpp/test/OpenSSLManualInitTest.cpp
+++ b/lib/cpp/test/OpenSSLManualInitTest.cpp
@@ -69,7 +69,8 @@ void test_openssl_availability() {
boost::unit_test::test_suite* init_unit_test_suite(int argc, char* argv[]) {
THRIFT_UNUSED_VARIABLE(argc);
THRIFT_UNUSED_VARIABLE(argv);
- boost::unit_test::test_suite* suite = &boost::unit_test::framework::master_test_suite();
+ boost::unit_test::test_suite* suite =
+ &boost::unit_test::framework::master_test_suite();
suite->p_name.value = "OpenSSLManualInit";
suite->add(BOOST_TEST_CASE(test_openssl_availability));
http://git-wip-us.apache.org/repos/asf/thrift/blob/240120c8/lib/cpp/test/OptionalRequiredTest.cpp
----------------------------------------------------------------------
diff --git a/lib/cpp/test/OptionalRequiredTest.cpp b/lib/cpp/test/OptionalRequiredTest.cpp
index 79fa697..44b6885 100644
--- a/lib/cpp/test/OptionalRequiredTest.cpp
+++ b/lib/cpp/test/OptionalRequiredTest.cpp
@@ -38,6 +38,7 @@ using namespace apache::thrift;
using namespace apache::thrift::transport;
using namespace apache::thrift::protocol;
+
/*
template<typename Struct>
void trywrite(const Struct& s, bool should_work) {
@@ -54,12 +55,13 @@ void trywrite(const Struct& s, bool should_work) {
*/
template <typename Struct1, typename Struct2>
-void write_to_read(const Struct1& w, Struct2& r) {
+void write_to_read(const Struct1 & w, Struct2 & r) {
TBinaryProtocol protocol(boost::shared_ptr<TTransport>(new TMemoryBuffer));
w.write(&protocol);
r.read(&protocol);
}
+
int main() {
cout << "This old school struct should have three fields." << endl;
@@ -96,22 +98,22 @@ int main() {
Simple s1, s2, s3;
s1.im_optional = 10;
assert(!s1.__isset.im_default);
- // assert(!s1.__isset.im_required); // Compile error.
+ //assert(!s1.__isset.im_required); // Compile error.
assert(!s1.__isset.im_optional);
write_to_read(s1, s2);
- assert(s2.__isset.im_default);
- // assert( s2.__isset.im_required); // Compile error.
+ assert( s2.__isset.im_default);
+ //assert( s2.__isset.im_required); // Compile error.
assert(!s2.__isset.im_optional);
assert(s3.im_optional == 0);
s1.__isset.im_optional = true;
write_to_read(s1, s3);
- assert(s3.__isset.im_default);
- // assert( s3.__isset.im_required); // Compile error.
- assert(s3.__isset.im_optional);
+ assert( s3.__isset.im_default);
+ //assert( s3.__isset.im_required); // Compile error.
+ assert( s3.__isset.im_optional);
assert(s3.im_optional == 10);
}
@@ -124,7 +126,7 @@ int main() {
write_to_read(t2, t1);
write_to_read(t1, t2);
assert(!t1.__isset.im_default);
- assert(t2.__isset.im_optional);
+ assert( t2.__isset.im_optional);
assert(t1.im_default == t2.im_optional);
assert(t1.im_default == 0);
}
@@ -154,8 +156,8 @@ int main() {
try {
write_to_read(t2, t3);
abort();
- } catch (const TProtocolException&) {
}
+ catch (const TProtocolException&) {}
write_to_read(t3, t2);
assert(t2.__isset.im_optional);
@@ -167,6 +169,7 @@ int main() {
cout << ThriftDebugString(c) << endl;
}
+
{
Tricky1 t1;
Tricky2 t2;
@@ -191,12 +194,12 @@ int main() {
assert(o1 == o2);
o1.__isset.im_str = o2.__isset.im_str = true;
assert(o1 == o2);
- map<int32_t, string> mymap;
+ map<int32_t,string> mymap;
mymap[1] = "bar";
mymap[2] = "baz";
- o1.im_big.push_back(map<int32_t, string>());
+ o1.im_big.push_back(map<int32_t,string>());
assert(o1 != o2);
- o2.im_big.push_back(map<int32_t, string>());
+ o2.im_big.push_back(map<int32_t,string>());
assert(o1 == o2);
o2.im_big.push_back(mymap);
assert(o1 != o2);
@@ -217,7 +220,7 @@ int main() {
o3.im_big.push_back(mymap);
assert(o1 == o3);
- // cout << ThriftDebugString(o3) << endl;
+ //cout << ThriftDebugString(o3) << endl;
}
{
http://git-wip-us.apache.org/repos/asf/thrift/blob/240120c8/lib/cpp/test/RWMutexStarveTest.cpp
----------------------------------------------------------------------
diff --git a/lib/cpp/test/RWMutexStarveTest.cpp b/lib/cpp/test/RWMutexStarveTest.cpp
index 32c1531..e6cccf2 100644
--- a/lib/cpp/test/RWMutexStarveTest.cpp
+++ b/lib/cpp/test/RWMutexStarveTest.cpp
@@ -33,13 +33,16 @@ using boost::unit_test::framework::master_test_suite;
using namespace apache::thrift::concurrency;
using namespace std;
-class Locker : public Runnable {
+class Locker : public Runnable
+{
protected:
- Locker(boost::shared_ptr<ReadWriteMutex> rwlock, bool writer)
- : rwlock_(rwlock), writer_(writer), started_(false), gotLock_(false), signaled_(false) {}
+ Locker(boost::shared_ptr<ReadWriteMutex> rwlock, bool writer) :
+ rwlock_(rwlock), writer_(writer),
+ started_(false), gotLock_(false), signaled_(false) { }
public:
- virtual void run() {
+ virtual void run()
+ {
started_ = true;
if (writer_) {
rwlock_->acquireWrite();
@@ -65,17 +68,20 @@ protected:
volatile bool signaled_;
};
-class Reader : public Locker {
+class Reader : public Locker
+{
public:
- Reader(boost::shared_ptr<ReadWriteMutex> rwlock) : Locker(rwlock, false) {}
+ Reader(boost::shared_ptr<ReadWriteMutex> rwlock) : Locker(rwlock, false) { }
};
-class Writer : public Locker {
+class Writer : public Locker
+{
public:
- Writer(boost::shared_ptr<ReadWriteMutex> rwlock) : Locker(rwlock, true) {}
+ Writer(boost::shared_ptr<ReadWriteMutex> rwlock) : Locker(rwlock, true) { }
};
-void test_starve(PosixThreadFactory::POLICY policy) {
+void test_starve(PosixThreadFactory::POLICY policy)
+{
// the man pages for pthread_wrlock_rdlock suggest that any OS guarantee about
// writer starvation may be influenced by the scheduling policy, so let's try
// all 3 policies to see if any of them work.
@@ -142,17 +148,20 @@ void test_starve(PosixThreadFactory::POLICY policy) {
BOOST_CHECK_MESSAGE(success, "writer is starving");
}
-BOOST_AUTO_TEST_SUITE(RWMutexStarveTest)
+BOOST_AUTO_TEST_SUITE( RWMutexStarveTest )
-BOOST_AUTO_TEST_CASE(test_starve_other) {
+BOOST_AUTO_TEST_CASE( test_starve_other )
+{
test_starve(PosixThreadFactory::OTHER);
}
-BOOST_AUTO_TEST_CASE(test_starve_rr) {
+BOOST_AUTO_TEST_CASE( test_starve_rr )
+{
test_starve(PosixThreadFactory::ROUND_ROBIN);
}
-BOOST_AUTO_TEST_CASE(test_starve_fifo) {
+BOOST_AUTO_TEST_CASE( test_starve_fifo )
+{
test_starve(PosixThreadFactory::FIFO);
}
http://git-wip-us.apache.org/repos/asf/thrift/blob/240120c8/lib/cpp/test/RecursiveTest.cpp
----------------------------------------------------------------------
diff --git a/lib/cpp/test/RecursiveTest.cpp b/lib/cpp/test/RecursiveTest.cpp
index a74be91..24c0f7c 100644
--- a/lib/cpp/test/RecursiveTest.cpp
+++ b/lib/cpp/test/RecursiveTest.cpp
@@ -27,7 +27,7 @@
using apache::thrift::transport::TMemoryBuffer;
using apache::thrift::protocol::TBinaryProtocol;
-using boost::shared_ptr;
+ using boost::shared_ptr;
int main() {
shared_ptr<TMemoryBuffer> buf(new TMemoryBuffer());
@@ -71,4 +71,5 @@ int main() {
assert(false);
} catch (const apache::thrift::protocol::TProtocolException& e) {
}
+
}
http://git-wip-us.apache.org/repos/asf/thrift/blob/240120c8/lib/cpp/test/SpecializationTest.cpp
----------------------------------------------------------------------
diff --git a/lib/cpp/test/SpecializationTest.cpp b/lib/cpp/test/SpecializationTest.cpp
index 856bdac..0bef12a 100644
--- a/lib/cpp/test/SpecializationTest.cpp
+++ b/lib/cpp/test/SpecializationTest.cpp
@@ -12,20 +12,20 @@ using namespace apache::thrift::transport;
using namespace apache::thrift::protocol;
typedef TBinaryProtocolT<TMemoryBuffer> MyProtocol;
-// typedef TBinaryProtocolT<TTransport> MyProtocol;
+//typedef TBinaryProtocolT<TTransport> MyProtocol;
int main() {
OneOfEach ooe;
- ooe.im_true = true;
- ooe.im_false = false;
- ooe.a_bite = 0x7f;
+ ooe.im_true = true;
+ ooe.im_false = false;
+ ooe.a_bite = 0x7f;
ooe.integer16 = 27000;
- ooe.integer32 = 1 << 24;
+ ooe.integer32 = 1<<24;
ooe.integer64 = (uint64_t)6000 * 1000 * 1000;
ooe.double_precision = M_PI;
- ooe.some_characters = "JSON THIS! \"\1";
- ooe.zomg_unicode = "\xd7\n\a\t";
+ ooe.some_characters = "JSON THIS! \"\1";
+ ooe.zomg_unicode = "\xd7\n\a\t";
ooe.base64 = "\1\2\3\255";
Nesting n;
@@ -33,12 +33,12 @@ int main() {
n.my_ooe.integer16 = 16;
n.my_ooe.integer32 = 32;
n.my_ooe.integer64 = 64;
- n.my_ooe.double_precision = (std::sqrt(5.0) + 1) / 2;
- n.my_ooe.some_characters = ":R (me going \"rrrr\")";
+ n.my_ooe.double_precision = (std::sqrt(5.0)+1)/2;
+ n.my_ooe.some_characters = ":R (me going \"rrrr\")";
n.my_ooe.zomg_unicode = "\xd3\x80\xe2\x85\xae\xce\x9d\x20"
"\xd0\x9d\xce\xbf\xe2\x85\xbf\xd0\xbe\xc9\xa1\xd0\xb3\xd0\xb0\xcf\x81\xe2\x84\x8e"
"\x20\xce\x91\x74\x74\xce\xb1\xe2\x85\xbd\xce\xba\xc7\x83\xe2\x80\xbc";
- n.my_bonk.type = 31337;
+ n.my_bonk.type = 31337;
n.my_bonk.message = "I am a bonk... xor!";
HolyMoley hm;
@@ -62,21 +62,21 @@ int main() {
std::vector<Bonk> stage2;
hm.bonks["nothing"] = stage2;
- stage2.resize(stage2.size() + 1);
+ stage2.resize(stage2.size()+1);
stage2.back().type = 1;
stage2.back().message = "Wait.";
- stage2.resize(stage2.size() + 1);
+ stage2.resize(stage2.size()+1);
stage2.back().type = 2;
stage2.back().message = "What?";
hm.bonks["something"] = stage2;
stage2.clear();
- stage2.resize(stage2.size() + 1);
+ stage2.resize(stage2.size()+1);
stage2.back().type = 3;
stage2.back().message = "quoth";
- stage2.resize(stage2.size() + 1);
+ stage2.resize(stage2.size()+1);
stage2.back().type = 4;
stage2.back().message = "the raven";
- stage2.resize(stage2.size() + 1);
+ stage2.resize(stage2.size()+1);
stage2.back().type = 5;
stage2.back().message = "nevermore";
hm.bonks["poe"] = stage2;
@@ -92,6 +92,7 @@ int main() {
assert(ooe == ooe2);
+
cout << "Testing hm" << endl;
hm.write(proto.get());
http://git-wip-us.apache.org/repos/asf/thrift/blob/240120c8/lib/cpp/test/TFDTransportTest.cpp
----------------------------------------------------------------------
diff --git a/lib/cpp/test/TFDTransportTest.cpp b/lib/cpp/test/TFDTransportTest.cpp
index 9d2bd90..7b962d8 100644
--- a/lib/cpp/test/TFDTransportTest.cpp
+++ b/lib/cpp/test/TFDTransportTest.cpp
@@ -25,10 +25,13 @@
using apache::thrift::transport::TTransportException;
using apache::thrift::transport::TFDTransport;
-class DummyException : std::exception {};
+class DummyException : std::exception {
+};
int main() {
- { TFDTransport t(256, TFDTransport::NO_CLOSE_ON_DESTROY); }
+ {
+ TFDTransport t(256, TFDTransport::NO_CLOSE_ON_DESTROY);
+ }
try {
{
@@ -53,4 +56,5 @@ int main() {
}
return 0;
+
}
http://git-wip-us.apache.org/repos/asf/thrift/blob/240120c8/lib/cpp/test/TFileTransportTest.cpp
----------------------------------------------------------------------
diff --git a/lib/cpp/test/TFileTransportTest.cpp b/lib/cpp/test/TFileTransportTest.cpp
old mode 100644
new mode 100755
index 294c9a6..67e05e3
--- a/lib/cpp/test/TFileTransportTest.cpp
+++ b/lib/cpp/test/TFileTransportTest.cpp
@@ -41,6 +41,7 @@ static const char* tmp_dir = "/tmp";
class FsyncLog;
FsyncLog* fsync_log;
+
/**************************************************************************
* Helper code
**************************************************************************/
@@ -48,11 +49,11 @@ FsyncLog* fsync_log;
// Provide BOOST_WARN_LT() and BOOST_WARN_GT(), in case we're compiled
// with an older version of boost
#ifndef BOOST_WARN_LT
-#define BOOST_WARN_CMP(a, b, op, check_fn) \
- check_fn((a)op(b), \
- "check " BOOST_STRINGIZE(a) " " BOOST_STRINGIZE(op) " " BOOST_STRINGIZE( \
- b) " failed: " BOOST_STRINGIZE(a) "=" \
- << (a) << " " BOOST_STRINGIZE(b) "=" << (b))
+#define BOOST_WARN_CMP(a, b, op, check_fn) \
+ check_fn((a) op (b), \
+ "check " BOOST_STRINGIZE(a) " " BOOST_STRINGIZE(op) " " \
+ BOOST_STRINGIZE(b) " failed: " BOOST_STRINGIZE(a) "=" << (a) << \
+ " " BOOST_STRINGIZE(b) "=" << (b))
#define BOOST_WARN_LT(a, b) BOOST_WARN_CMP(a, b, <, BOOST_WARN_MESSAGE)
#define BOOST_WARN_GT(a, b) BOOST_WARN_CMP(a, b, >, BOOST_WARN_MESSAGE)
@@ -63,7 +64,7 @@ FsyncLog* fsync_log;
* Class to record calls to fsync
*/
class FsyncLog {
-public:
+ public:
struct FsyncCall {
struct timeval time;
int fd;
@@ -73,15 +74,17 @@ public:
FsyncLog() {}
void fsync(int fd) {
- (void)fd;
+ (void) fd;
FsyncCall call;
gettimeofday(&call.time, NULL);
calls_.push_back(call);
}
- const CallList* getCalls() const { return &calls_; }
+ const CallList* getCalls() const {
+ return &calls_;
+ }
-private:
+ private:
CallList calls_;
};
@@ -89,7 +92,7 @@ private:
* Helper class to clean up temporary files
*/
class TempFile {
-public:
+ public:
TempFile(const char* directory, const char* prefix) {
size_t path_len = strlen(directory) + strlen(prefix) + 8;
path_ = new char[path_len];
@@ -106,9 +109,13 @@ public:
close();
}
- const char* getPath() const { return path_; }
+ const char* getPath() const {
+ return path_;
+ }
- int getFD() const { return fd_; }
+ int getFD() const {
+ return fd_;
+ }
void unlink() {
if (path_) {
@@ -127,7 +134,7 @@ public:
fd_ = -1;
}
-private:
+ private:
char* path_;
int fd_;
};
@@ -135,7 +142,8 @@ private:
// Use our own version of fsync() for testing.
// This returns immediately, so timing in test_destructor() isn't affected by
// waiting on the actual filesystem.
-extern "C" int fsync(int fd) {
+extern "C"
+int fsync(int fd) {
if (fsync_log) {
fsync_log->fsync(fd);
}
@@ -146,6 +154,7 @@ int time_diff(const struct timeval* t1, const struct timeval* t2) {
return (t2->tv_usec - t1->tv_usec) + (t2->tv_sec - t1->tv_sec) * 1000000;
}
+
/**************************************************************************
* Test cases
**************************************************************************/
@@ -212,7 +221,8 @@ BOOST_AUTO_TEST_CASE(test_destructor) {
/**
* Make sure setFlushMaxUs() is honored.
*/
-void test_flush_max_us_impl(uint32_t flush_us, uint32_t write_us, uint32_t test_us) {
+void test_flush_max_us_impl(uint32_t flush_us, uint32_t write_us,
+ uint32_t test_us) {
// TFileTransport only calls fsync() if data has been written,
// so make sure the write interval is smaller than the flush interval.
BOOST_WARN(write_us < flush_us);
@@ -267,10 +277,13 @@ void test_flush_max_us_impl(uint32_t flush_us, uint32_t write_us, uint32_t test_
const FsyncLog::CallList* calls = log.getCalls();
// We added 1 fsync call above.
// Make sure TFileTransport called fsync at least once
- BOOST_WARN_GE(calls->size(), static_cast<FsyncLog::CallList::size_type>(1));
+ BOOST_WARN_GE(calls->size(),
+ static_cast<FsyncLog::CallList::size_type>(1));
const struct timeval* prev_time = NULL;
- for (FsyncLog::CallList::const_iterator it = calls->begin(); it != calls->end(); ++it) {
+ for (FsyncLog::CallList::const_iterator it = calls->begin();
+ it != calls->end();
+ ++it) {
if (prev_time) {
int delta = time_diff(prev_time, &it->time);
BOOST_WARN_LT(delta, max_allowed_delta);
@@ -339,8 +352,11 @@ void print_usage(FILE* f, const char* argv0) {
}
void parse_args(int argc, char* argv[]) {
- struct option long_opts[]
- = {{"help", false, NULL, 'h'}, {"tmp-dir", true, NULL, 't'}, {NULL, 0, NULL, 0}};
+ struct option long_opts[] = {
+ { "help", false, NULL, 'h' },
+ { "tmp-dir", true, NULL, 't' },
+ { NULL, 0, NULL, 0 }
+ };
while (true) {
optopt = 1;
@@ -350,25 +366,26 @@ void parse_args(int argc, char* argv[]) {
}
switch (optchar) {
- case 't':
- tmp_dir = optarg;
- break;
- case 'h':
- print_usage(stdout, argv[0]);
- exit(0);
- case '?':
- exit(1);
- default:
- // Only happens if someone adds another option to the optarg string,
- // but doesn't update the switch statement to handle it.
- fprintf(stderr, "unknown option \"-%c\"\n", optchar);
- exit(1);
+ case 't':
+ tmp_dir = optarg;
+ break;
+ case 'h':
+ print_usage(stdout, argv[0]);
+ exit(0);
+ case '?':
+ exit(1);
+ default:
+ // Only happens if someone adds another option to the optarg string,
+ // but doesn't update the switch statement to handle it.
+ fprintf(stderr, "unknown option \"-%c\"\n", optchar);
+ exit(1);
}
}
}
boost::unit_test::test_suite* init_unit_test_suite(int argc, char* argv[]) {
- boost::unit_test::framework::master_test_suite().p_name.value = "TFileTransportTest";
+ boost::unit_test::framework::master_test_suite().p_name.value =
+ "TFileTransportTest";
// Parse arguments
parse_args(argc, argv);
http://git-wip-us.apache.org/repos/asf/thrift/blob/240120c8/lib/cpp/test/TMemoryBufferTest.cpp
----------------------------------------------------------------------
diff --git a/lib/cpp/test/TMemoryBufferTest.cpp b/lib/cpp/test/TMemoryBufferTest.cpp
index cf49477..b81a667 100644
--- a/lib/cpp/test/TMemoryBufferTest.cpp
+++ b/lib/cpp/test/TMemoryBufferTest.cpp
@@ -25,84 +25,84 @@
#include <thrift/protocol/TBinaryProtocol.h>
#include "gen-cpp/ThriftTest_types.h"
-BOOST_AUTO_TEST_SUITE(TMemoryBufferTest)
-
-BOOST_AUTO_TEST_CASE(test_roundtrip) {
- using apache::thrift::transport::TMemoryBuffer;
- using apache::thrift::protocol::TBinaryProtocol;
- using boost::shared_ptr;
-
- shared_ptr<TMemoryBuffer> strBuffer(new TMemoryBuffer());
- shared_ptr<TBinaryProtocol> binaryProtcol(new TBinaryProtocol(strBuffer));
-
- thrift::test::Xtruct a;
- a.i32_thing = 10;
- a.i64_thing = 30;
- a.string_thing = "holla back a";
-
- a.write(binaryProtcol.get());
- std::string serialized = strBuffer->getBufferAsString();
-
- shared_ptr<TMemoryBuffer> strBuffer2(new TMemoryBuffer());
- shared_ptr<TBinaryProtocol> binaryProtcol2(new TBinaryProtocol(strBuffer2));
-
- strBuffer2->resetBuffer((uint8_t*)serialized.data(), static_cast<uint32_t>(serialized.length()));
- thrift::test::Xtruct a2;
- a2.read(binaryProtcol2.get());
-
- assert(a == a2);
-}
-
-BOOST_AUTO_TEST_CASE(test_copy) {
- using apache::thrift::transport::TMemoryBuffer;
- using std::string;
- using std::cout;
- using std::endl;
-
- string* str1 = new string("abcd1234");
- const char* data1 = str1->data();
- TMemoryBuffer buf((uint8_t*)str1->data(),
- static_cast<uint32_t>(str1->length()),
- TMemoryBuffer::COPY);
- delete str1;
- string* str2 = new string("plsreuse");
- bool obj_reuse = (str1 == str2);
- bool dat_reuse = (data1 == str2->data());
- cout << "Object reuse: " << obj_reuse << " Data reuse: " << dat_reuse
- << ((obj_reuse && dat_reuse) ? " YAY!" : "") << endl;
- delete str2;
-
- string str3 = "wxyz", str4 = "6789";
- buf.readAppendToString(str3, 4);
- buf.readAppendToString(str4, INT_MAX);
-
- assert(str3 == "wxyzabcd");
- assert(str4 == "67891234");
-}
-
-BOOST_AUTO_TEST_CASE(test_exceptions) {
- using apache::thrift::transport::TTransportException;
- using apache::thrift::transport::TMemoryBuffer;
- using std::string;
-
- char data[] = "foo\0bar";
-
- TMemoryBuffer buf1((uint8_t*)data, 7, TMemoryBuffer::OBSERVE);
- string str = buf1.getBufferAsString();
- assert(str.length() == 7);
- buf1.resetBuffer();
- try {
- buf1.write((const uint8_t*)"foo", 3);
- assert(false);
- } catch (TTransportException&) {
+BOOST_AUTO_TEST_SUITE( TMemoryBufferTest )
+
+BOOST_AUTO_TEST_CASE( test_roundtrip ) {
+ using apache::thrift::transport::TMemoryBuffer;
+ using apache::thrift::protocol::TBinaryProtocol;
+ using boost::shared_ptr;
+
+ shared_ptr<TMemoryBuffer> strBuffer(new TMemoryBuffer());
+ shared_ptr<TBinaryProtocol> binaryProtcol(new TBinaryProtocol(strBuffer));
+
+ thrift::test::Xtruct a;
+ a.i32_thing = 10;
+ a.i64_thing = 30;
+ a.string_thing ="holla back a";
+
+ a.write(binaryProtcol.get());
+ std::string serialized = strBuffer->getBufferAsString();
+
+ shared_ptr<TMemoryBuffer> strBuffer2(new TMemoryBuffer());
+ shared_ptr<TBinaryProtocol> binaryProtcol2(new TBinaryProtocol(strBuffer2));
+
+ strBuffer2->resetBuffer((uint8_t*)serialized.data(), static_cast<uint32_t>(serialized.length()));
+ thrift::test::Xtruct a2;
+ a2.read(binaryProtcol2.get());
+
+ assert(a == a2);
}
- TMemoryBuffer buf2((uint8_t*)data, 7, TMemoryBuffer::COPY);
- try {
- buf2.write((const uint8_t*)"bar", 3);
- } catch (TTransportException&) {
- assert(false);
+BOOST_AUTO_TEST_CASE( test_copy )
+ {
+ using apache::thrift::transport::TMemoryBuffer;
+ using std::string;
+ using std::cout;
+ using std::endl;
+
+ string* str1 = new string("abcd1234");
+ const char* data1 = str1->data();
+ TMemoryBuffer buf((uint8_t*)str1->data(), static_cast<uint32_t>(str1->length()), TMemoryBuffer::COPY);
+ delete str1;
+ string* str2 = new string("plsreuse");
+ bool obj_reuse = (str1 == str2);
+ bool dat_reuse = (data1 == str2->data());
+ cout << "Object reuse: " << obj_reuse << " Data reuse: " << dat_reuse
+ << ((obj_reuse && dat_reuse) ? " YAY!" : "") << endl;
+ delete str2;
+
+ string str3 = "wxyz", str4 = "6789";
+ buf.readAppendToString(str3, 4);
+ buf.readAppendToString(str4, INT_MAX);
+
+ assert(str3 == "wxyzabcd");
+ assert(str4 == "67891234");
+ }
+
+BOOST_AUTO_TEST_CASE( test_exceptions )
+ {
+ using apache::thrift::transport::TTransportException;
+ using apache::thrift::transport::TMemoryBuffer;
+ using std::string;
+
+ char data[] = "foo\0bar";
+
+ TMemoryBuffer buf1((uint8_t*)data, 7, TMemoryBuffer::OBSERVE);
+ string str = buf1.getBufferAsString();
+ assert(str.length() == 7);
+ buf1.resetBuffer();
+ try {
+ buf1.write((const uint8_t*)"foo", 3);
+ assert(false);
+ } catch (TTransportException&) {}
+
+ TMemoryBuffer buf2((uint8_t*)data, 7, TMemoryBuffer::COPY);
+ try {
+ buf2.write((const uint8_t*)"bar", 3);
+ } catch (TTransportException&) {
+ assert(false);
+ }
}
-}
BOOST_AUTO_TEST_SUITE_END()
+
http://git-wip-us.apache.org/repos/asf/thrift/blob/240120c8/lib/cpp/test/TPipedTransportTest.cpp
----------------------------------------------------------------------
diff --git a/lib/cpp/test/TPipedTransportTest.cpp b/lib/cpp/test/TPipedTransportTest.cpp
index 53a6fb5..7762f05 100644
--- a/lib/cpp/test/TPipedTransportTest.cpp
+++ b/lib/cpp/test/TPipedTransportTest.cpp
@@ -36,17 +36,18 @@ int main() {
underlying->write((uint8_t*)"abcd", 4);
trans->readAll(buffer, 2);
- assert(string((char*)buffer, 2) == "ab");
+ assert( string((char*)buffer, 2) == "ab" );
trans->readEnd();
- assert(pipe->getBufferAsString() == "ab");
+ assert( pipe->getBufferAsString() == "ab" );
pipe->resetBuffer();
underlying->write((uint8_t*)"ef", 2);
trans->readAll(buffer, 2);
- assert(string((char*)buffer, 2) == "cd");
+ assert( string((char*)buffer, 2) == "cd" );
trans->readAll(buffer, 2);
- assert(string((char*)buffer, 2) == "ef");
+ assert( string((char*)buffer, 2) == "ef" );
trans->readEnd();
- assert(pipe->getBufferAsString() == "cdef");
+ assert( pipe->getBufferAsString() == "cdef" );
return 0;
+
}
http://git-wip-us.apache.org/repos/asf/thrift/blob/240120c8/lib/cpp/test/ThriftTest_extras.cpp
----------------------------------------------------------------------
diff --git a/lib/cpp/test/ThriftTest_extras.cpp b/lib/cpp/test/ThriftTest_extras.cpp
index af5606e..33f681f 100644
--- a/lib/cpp/test/ThriftTest_extras.cpp
+++ b/lib/cpp/test/ThriftTest_extras.cpp
@@ -22,12 +22,12 @@
#include <thrift/protocol/TDebugProtocol.h>
#include "gen-cpp/ThriftTest_types.h"
-namespace thrift {
-namespace test {
+
+namespace thrift { namespace test {
bool Insanity::operator<(thrift::test::Insanity const& other) const {
using apache::thrift::ThriftDebugString;
return ThriftDebugString(*this) < ThriftDebugString(other);
}
-}
-}
+
+}}
http://git-wip-us.apache.org/repos/asf/thrift/blob/240120c8/lib/cpp/test/ToStringTest.cpp
----------------------------------------------------------------------
diff --git a/lib/cpp/test/ToStringTest.cpp b/lib/cpp/test/ToStringTest.cpp
index d204cb3..1a89c11 100644
--- a/lib/cpp/test/ToStringTest.cpp
+++ b/lib/cpp/test/ToStringTest.cpp
@@ -30,9 +30,9 @@
using apache::thrift::to_string;
-BOOST_AUTO_TEST_SUITE(ToStringTest)
+BOOST_AUTO_TEST_SUITE( ToStringTest )
-BOOST_AUTO_TEST_CASE(base_types_to_string) {
+BOOST_AUTO_TEST_CASE( base_types_to_string ) {
BOOST_CHECK_EQUAL(to_string(10), "10");
BOOST_CHECK_EQUAL(to_string(true), "1");
BOOST_CHECK_EQUAL(to_string('a'), "a");
@@ -40,91 +40,91 @@ BOOST_AUTO_TEST_CASE(base_types_to_string) {
BOOST_CHECK_EQUAL(to_string("abc"), "abc");
}
-BOOST_AUTO_TEST_CASE(empty_vector_to_string) {
+BOOST_AUTO_TEST_CASE( empty_vector_to_string ) {
std::vector<int> l;
BOOST_CHECK_EQUAL(to_string(l), "[]");
}
-BOOST_AUTO_TEST_CASE(single_item_vector_to_string) {
+BOOST_AUTO_TEST_CASE( single_item_vector_to_string ) {
std::vector<int> l;
l.push_back(100);
BOOST_CHECK_EQUAL(to_string(l), "[100]");
}
-BOOST_AUTO_TEST_CASE(multiple_item_vector_to_string) {
+BOOST_AUTO_TEST_CASE( multiple_item_vector_to_string ) {
std::vector<int> l;
l.push_back(100);
l.push_back(150);
BOOST_CHECK_EQUAL(to_string(l), "[100, 150]");
}
-BOOST_AUTO_TEST_CASE(empty_map_to_string) {
+BOOST_AUTO_TEST_CASE( empty_map_to_string ) {
std::map<int, std::string> m;
BOOST_CHECK_EQUAL(to_string(m), "{}");
}
-BOOST_AUTO_TEST_CASE(single_item_map_to_string) {
+BOOST_AUTO_TEST_CASE( single_item_map_to_string ) {
std::map<int, std::string> m;
m[12] = "abc";
BOOST_CHECK_EQUAL(to_string(m), "{12: abc}");
}
-BOOST_AUTO_TEST_CASE(multi_item_map_to_string) {
+BOOST_AUTO_TEST_CASE( multi_item_map_to_string ) {
std::map<int, std::string> m;
m[12] = "abc";
m[31] = "xyz";
BOOST_CHECK_EQUAL(to_string(m), "{12: abc, 31: xyz}");
}
-BOOST_AUTO_TEST_CASE(empty_set_to_string) {
+BOOST_AUTO_TEST_CASE( empty_set_to_string ) {
std::set<char> s;
BOOST_CHECK_EQUAL(to_string(s), "{}");
}
-BOOST_AUTO_TEST_CASE(single_item_set_to_string) {
+BOOST_AUTO_TEST_CASE( single_item_set_to_string ) {
std::set<char> s;
s.insert('c');
BOOST_CHECK_EQUAL(to_string(s), "{c}");
}
-BOOST_AUTO_TEST_CASE(multi_item_set_to_string) {
+BOOST_AUTO_TEST_CASE( multi_item_set_to_string ) {
std::set<char> s;
s.insert('a');
s.insert('z');
BOOST_CHECK_EQUAL(to_string(s), "{a, z}");
}
-BOOST_AUTO_TEST_CASE(generated_empty_object_to_string) {
+BOOST_AUTO_TEST_CASE( generated_empty_object_to_string ) {
thrift::test::EmptyStruct e;
BOOST_CHECK_EQUAL(to_string(e), "EmptyStruct()");
}
-BOOST_AUTO_TEST_CASE(generated_single_basic_field_object_to_string) {
+BOOST_AUTO_TEST_CASE( generated_single_basic_field_object_to_string ) {
thrift::test::StructA a;
a.__set_s("abcd");
BOOST_CHECK_EQUAL(to_string(a), "StructA(s=abcd)");
}
-BOOST_AUTO_TEST_CASE(generated_two_basic_fields_object_to_string) {
+BOOST_AUTO_TEST_CASE( generated_two_basic_fields_object_to_string ) {
thrift::test::Bonk a;
a.__set_message("abcd");
a.__set_type(1234);
BOOST_CHECK_EQUAL(to_string(a), "Bonk(message=abcd, type=1234)");
}
-BOOST_AUTO_TEST_CASE(generated_optional_fields_object_to_string) {
+BOOST_AUTO_TEST_CASE( generated_optional_fields_object_to_string ) {
thrift::test::Tricky2 a;
BOOST_CHECK_EQUAL(to_string(a), "Tricky2(im_optional=<null>)");
a.__set_im_optional(123);
BOOST_CHECK_EQUAL(to_string(a), "Tricky2(im_optional=123)");
}
-BOOST_AUTO_TEST_CASE(generated_nested_object_to_string) {
+BOOST_AUTO_TEST_CASE( generated_nested_object_to_string ) {
thrift::test::OneField a;
BOOST_CHECK_EQUAL(to_string(a), "OneField(field=EmptyStruct())");
}
-BOOST_AUTO_TEST_CASE(generated_nested_list_object_to_string) {
+BOOST_AUTO_TEST_CASE( generated_nested_list_object_to_string ) {
thrift::test::ListBonks l;
l.bonk.assign(2, thrift::test::Bonk());
l.bonk[0].__set_message("a");