~linuxjedi/libdrizzle/5.1-fix-mingw

« back to all changes in this revision

Viewing changes to tests/unit/binlog.cc

  • Committer: Continuous Integration
  • Date: 2013-01-27 05:23:57 UTC
  • mfrom: (98.1.2 5.1-binlog-callback)
  • Revision ID: ci@drizzle.org-20130127052357-jb87upa8hd75wfyu
Merge lp:~linuxjedi/libdrizzle/5.1-binlog-callback Build: jenkins-Libdrizzle-57

Show diffs side-by-side

added added

removed removed

Lines of Context:
45
45
#include <cstdio>
46
46
#include <cstdlib>
47
47
 
 
48
void binlog_error(drizzle_return_t ret, void *context)
 
49
{
 
50
  (void) context;
 
51
  ASSERT_EQ_(DRIZZLE_RETURN_EOF, ret, "%s(%s)", drizzle_error(con), drizzle_strerror(ret));
 
52
}
 
53
 
 
54
void binlog_event(drizzle_binlog_event_st *event, void *context)
 
55
{
 
56
  (void) context;
 
57
  uint32_t timestamp;
 
58
  timestamp= drizzle_binlog_event_timestamp(event);
 
59
  /* Test to see if timestamp is greater than 2012-01-01 00:00:00, corrupted
 
60
   * timestamps will have weird values that shoud fail this after several
 
61
   * events.  Also rotate event doesn't have a timestamp so need to add 0
 
62
   * to this test */
 
63
  ASSERT_FALSE_(((timestamp < 1325376000) && (timestamp != 0)), "Bad timestamp retrieved: %u", timestamp);
 
64
 
 
65
  /* An event higher than the max known is bad, either we don't know about
 
66
   * new events or type is corrupted */
 
67
  ASSERT_FALSE_((drizzle_binlog_event_type(event) >= DRIZZLE_EVENT_TYPE_END), "Bad event type: %d", drizzle_binlog_event_type(event));
 
68
}
 
69
 
48
70
int main(int argc, char *argv[])
49
71
{
50
72
  (void) argc;
51
73
  (void) argv;
 
74
  drizzle_binlog_st *binlog;
52
75
 
53
76
  con= drizzle_create_tcp(getenv("MYSQL_SERVER"),
54
77
                          getenv("MYSQL_PORT") ? atoi("MYSQL_PORT") : DRIZZLE_DEFAULT_TCP_PORT,
62
85
  drizzle_return_t ret= drizzle_connect(con);
63
86
  SKIP_IF_(ret == DRIZZLE_RETURN_COULD_NOT_CONNECT, "%s(%s)", drizzle_error(con), drizzle_strerror(ret));
64
87
  ASSERT_EQ_(DRIZZLE_RETURN_OK, ret, "%s(%s)", drizzle_error(con), drizzle_strerror(ret));
65
 
 
66
 
  drizzle_result_st *result= drizzle_start_binlog(con, 0, "", 0, true, &ret);
67
 
  ASSERT_TRUE(result);
 
88
  binlog= drizzle_binlog_init(con, binlog_event, binlog_error, NULL, true);
 
89
  ret= drizzle_binlog_start(binlog, 0, "", 0);
68
90
  SKIP_IF_(ret == DRIZZLE_RETURN_ERROR_CODE, "Binlog is not open?: %s(%s)", drizzle_error(con), drizzle_strerror(ret));
69
 
  ASSERT_EQ_(DRIZZLE_RETURN_OK, ret, "Drizzle binlog start failure: %s(%s)", drizzle_error(con), drizzle_strerror(ret));
70
 
 
71
 
  while (ret == DRIZZLE_RETURN_OK)
72
 
  {
73
 
    uint32_t timestamp;
74
 
    ret= drizzle_binlog_get_next_event(result);
75
 
    if (ret == DRIZZLE_RETURN_EOF)
76
 
    {
77
 
      break;
78
 
    }
79
 
    ASSERT_EQ_(DRIZZLE_RETURN_OK, ret, "Binlog error %s\n", drizzle_error(con));
80
 
    timestamp= drizzle_binlog_event_timestamp(result);
81
 
    /* Test to see if timestamp is greater than 2012-01-01 00:00:00, corrupted
82
 
     * timestamps will have weird values that shoud fail this after several
83
 
     * events.  Also rotate event doesn't have a timestamp so need to add 0
84
 
     * to this test */
85
 
    ASSERT_FALSE_(((timestamp < 1325376000) && (timestamp != 0)), "Bad timestamp retrieved: %u", timestamp);
86
 
 
87
 
    /* An event higher than the max known is bad, either we don't know about
88
 
     * new events or type is corrupted */
89
 
    ASSERT_FALSE_((drizzle_binlog_event_type(result) >= DRIZZLE_EVENT_TYPE_END), "Bad event type: %d", drizzle_binlog_event_type(result));
90
 
  }
91
 
 
 
91
  ASSERT_EQ_(DRIZZLE_RETURN_EOF, ret, "Drizzle binlog start failure: %s(%s)", drizzle_error(con), drizzle_strerror(ret));
92
92
  return EXIT_SUCCESS;
93
93
}