posix_spawn_file_actions_t file_actions;
posix_spawn_file_actions_init(&file_actions);
- stdin_fd.dup_for_spawn(Application::Pipe::READ, file_actions);
- stdout_fd.dup_for_spawn(Application::Pipe::WRITE, file_actions);
- stderr_fd.dup_for_spawn(Application::Pipe::WRITE, file_actions);
+ stdin_fd.dup_for_spawn(file_actions);
+ stdout_fd.dup_for_spawn(file_actions);
+ stderr_fd.dup_for_spawn(file_actions);
posix_spawnattr_t spawnattr;
posix_spawnattr_init(&spawnattr);
Application::Pipe::~Pipe()
{
- close(READ);
- close(WRITE);
+ if (_pipe_fd[0] != -1)
+ {
+ ::close(_pipe_fd[0]);
+ }
+
+ if (_pipe_fd[1] != -1)
+ {
+ ::close(_pipe_fd[1]);
+ }
}
-void Application::Pipe::dup_for_spawn(const close_t& arg, posix_spawn_file_actions_t& file_actions)
+void Application::Pipe::dup_for_spawn(posix_spawn_file_actions_t& file_actions)
{
- int type= int(arg);
+ int type= STDIN_FILENO == _std_fd ? 0 : 1;
int ret;
if ((ret= posix_spawn_file_actions_adddup2(&file_actions, _pipe_fd[type], _std_fd )) < 0)
void reset();
void close(const close_t& arg);
- void dup_for_spawn(const close_t& arg,
- posix_spawn_file_actions_t& file_actions);
+ void dup_for_spawn(posix_spawn_file_actions_t& file_actions);
void nonblock();
void cloexec();
return true;
}
+template <class T1_comparable, class T2_comparable>
+bool _compare_strcmp(const char *file, int line, const char *func, const T1_comparable& __expected, const T2_comparable& __actual)
+{
+ if (__expected == NULL)
+ {
+ fatal_message("Expected value was NULL, programmer error");
+ }
+
+ if (__actual == NULL)
+ {
+ libtest::stream::make_cerr(file, line, func) << "Expected " << __expected << " but got NULL";
+ return false;
+ }
+
+ if (strncmp(__expected, __actual, strlen(__expected)))
+ {
+ libtest::stream::make_cerr(file, line, func) << "Expected " << __expected << " passed \"" << __actual << "\"";
+ return false;
+ }
+
+ return true;
+}
+
template <class T_comparable>
bool _compare_zero(const char *file, int line, const char *func, T_comparable __actual)
{
} while (0)
-#define test_strcmp(A,B) \
+#define test_strcmp(__expected, __actual) \
do \
{ \
- if ((A) == NULL or (B) == NULL or strcmp((A), (B))) \
- { \
- if ((B) == NULL) fprintf(stderr, "\n%s:%d: Expected %s, got <null>\n", __FILE__, __LINE__, (A)); \
- else fprintf(stderr, "\n%s:%d: Expected %s, got \"%s\"\n", __FILE__, __LINE__, (A), (B)); \
- libtest::create_core(); \
- return TEST_FAILURE; \
- } \
+ void(libtest::_compare_strcmp(__FILE__, __LINE__, __func__, (__expected), (__actual))); \
} while (0)
#define test_memcmp(A,B,C) \
memcached_mget(memc, keys, key_length, 1));
memcached_return_t rc;
- memcached_result_st *results = memcached_fetch_result(memc, NULL, &rc);
+ memcached_result_st *results= memcached_fetch_result(memc, NULL, &rc);
test_true(results);
test_compare(MEMCACHED_SUCCESS, rc);
uint64_t cas_value= memcached_result_cas(results);
test_true(cas_value);
+ memcached_result_free(results);
+
// Bad cas value, sanity check
test_true(cas_value != 9999);
test_compare(MEMCACHED_END,