提交 bb5e8b9c 编写于 作者: I Ivan Leskin 提交者: Ashwin Agrawal

Add unit tests for rmgrdesc

Co-authored-by: NDavid Kimura <dkimura@pivotal.io>
上级 b74f174b
subdir=src/backend/access/rmgrdesc
top_builddir=../../../../..
include $(top_builddir)/src/Makefile.global
TARGETS=xactdesc
include $(top_builddir)/src/backend/mock.mk
#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
#include "cmockery.h"
#include "postgres.h"
#include "utils/memutils.h"
#include "access/xlog.h"
#include "pgtime.h"
/* Actual function body */
#include "../xactdesc.c"
static void
test_xactdescprepareCommit(void **state)
{
StringInfo buf = makeStringInfo();
XLogRecord *rec = palloc(SizeOfXLogRecord + MAXALIGN(sizeof(TwoPhaseFileHeader)));
rec->xl_info = XLOG_XACT_PREPARE;
TwoPhaseFileHeader* tpfh = (TwoPhaseFileHeader*) XLogRecGetData(rec);
tpfh->prepared_at = 617826371830030;
strcpy(tpfh->gid, "4242424242-0000000042");
tpfh->tablespace_oid_to_delete_on_commit = 42;
tpfh->tablespace_oid_to_delete_on_abort = InvalidOid;
xact_desc(buf, rec);
assert_string_equal("prepare: at = 2019-07-30 18:26:11.83003+00; gid = 4242424242-0000000042; tablespace_oid_to_delete_on_commit = 42", buf->data);
}
static void
test_xactdescprepareAbort(void **state)
{
StringInfo buf = makeStringInfo();
XLogRecord *rec = palloc(SizeOfXLogRecord + MAXALIGN(sizeof(TwoPhaseFileHeader)));
rec->xl_info = XLOG_XACT_PREPARE;
TwoPhaseFileHeader* tpfh = (TwoPhaseFileHeader*) XLogRecGetData(rec);
tpfh->prepared_at = 617826371830030;
strcpy(tpfh->gid, "4242424242-0000000042");
tpfh->tablespace_oid_to_delete_on_commit = InvalidOid;
tpfh->tablespace_oid_to_delete_on_abort = 42;
xact_desc(buf, rec);
assert_string_equal("prepare: at = 2019-07-30 18:26:11.83003+00; gid = 4242424242-0000000042; tablespace_oid_to_delete_on_abort = 42", buf->data);
}
static void
test_xactdescprepareNone(void **state)
{
StringInfo buf = makeStringInfo();
XLogRecord *rec = palloc(SizeOfXLogRecord + MAXALIGN(sizeof(TwoPhaseFileHeader)));
rec->xl_info = XLOG_XACT_PREPARE;
TwoPhaseFileHeader* tpfh = (TwoPhaseFileHeader*) XLogRecGetData(rec);
tpfh->prepared_at = 617826371830030;
strcpy(tpfh->gid, "4242424242-0000000042");
tpfh->tablespace_oid_to_delete_on_commit = InvalidOid;
tpfh->tablespace_oid_to_delete_on_abort = InvalidOid;
xact_desc(buf, rec);
assert_string_equal("prepare: at = 2019-07-30 18:26:11.83003+00; gid = 4242424242-0000000042", buf->data);
}
int
main(int argc, char* argv[])
{
cmockery_parse_arguments(argc, argv);
MemoryContextInit();
pg_timezone_initialize();
const UnitTest tests[] = {
unit_test(test_xactdescprepareCommit),
unit_test(test_xactdescprepareAbort),
unit_test(test_xactdescprepareNone)
};
return run_tests(tests);
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册