1 #include "clar_libgit2.h"
2 #include <git2/sys/config.h>
3 #include <git2/sys/odb_backend.h>
4 #include <git2/sys/refdb_backend.h>
6 #define STRINGIFY(s) #s
8 /* Checks two conditions for the specified structure:
9 * 1. That the initializers for the latest version produces the same
10 * in-memory representation.
11 * 2. That the function-based initializer supports all versions from 1...n,
12 * where n is the latest version (often represented by GIT_*_VERSION).
15 * structname: The name of the structure to test, e.g. git_blame_options.
16 * structver: The latest version of the specified structure.
17 * macroinit: The macro that initializes the latest version of the structure.
18 * funcinitname: The function that initializes the structure. Must have the
19 * signature "int (structname* instance, int version)".
21 #define CHECK_MACRO_FUNC_INIT_EQUAL(structname, structver, macroinit, funcinitname) \
23 structname structname##_macro_latest = macroinit; \
24 structname structname##_func_latest; \
25 int structname##_curr_ver = structver - 1; \
26 cl_git_pass(funcinitname(&structname##_func_latest, structver)); \
28 memcmp(&structname##_macro_latest, &structname##_func_latest, \
29 sizeof(structname)) == 0, \
30 "Macro-based and function-based initializer for " STRINGIFY(structname) \
31 " are not equivalent."); \
33 while (structname##_curr_ver > 0) \
36 cl_git_pass(funcinitname(¯o, structname##_curr_ver)); \
37 structname##_curr_ver--; \
41 void test_structinit_structinit__compare(void)
44 CHECK_MACRO_FUNC_INIT_EQUAL( \
45 git_blame_options
, GIT_BLAME_OPTIONS_VERSION
, \
46 GIT_BLAME_OPTIONS_INIT
, git_blame_init_options
);
49 CHECK_MACRO_FUNC_INIT_EQUAL( \
50 git_checkout_options
, GIT_CHECKOUT_OPTIONS_VERSION
, \
51 GIT_CHECKOUT_OPTIONS_INIT
, git_checkout_init_opts
);
54 CHECK_MACRO_FUNC_INIT_EQUAL( \
55 git_clone_options
, GIT_CLONE_OPTIONS_VERSION
, \
56 GIT_CLONE_OPTIONS_INIT
, git_clone_init_options
);
59 CHECK_MACRO_FUNC_INIT_EQUAL( \
60 git_diff_options
, GIT_DIFF_OPTIONS_VERSION
, \
61 GIT_DIFF_OPTIONS_INIT
, git_diff_init_options
);
64 CHECK_MACRO_FUNC_INIT_EQUAL( \
65 git_diff_find_options
, GIT_DIFF_FIND_OPTIONS_VERSION
, \
66 GIT_DIFF_FIND_OPTIONS_INIT
, git_diff_find_init_options
);
69 CHECK_MACRO_FUNC_INIT_EQUAL( \
70 git_merge_tree_opts
, GIT_MERGE_TREE_OPTS_VERSION
, \
71 GIT_MERGE_TREE_OPTS_INIT
, git_merge_tree_init_opts
);
74 CHECK_MACRO_FUNC_INIT_EQUAL( \
75 git_merge_opts
, GIT_MERGE_OPTS_VERSION
, \
76 GIT_MERGE_OPTS_INIT
, git_merge_init_opts
);
79 CHECK_MACRO_FUNC_INIT_EQUAL( \
80 git_push_options
, GIT_PUSH_OPTIONS_VERSION
, \
81 GIT_PUSH_OPTIONS_INIT
, git_push_init_options
);
84 CHECK_MACRO_FUNC_INIT_EQUAL( \
85 git_remote_callbacks
, GIT_REMOTE_CALLBACKS_VERSION
, \
86 GIT_REMOTE_CALLBACKS_INIT
, git_remote_init_callbacks
);
89 CHECK_MACRO_FUNC_INIT_EQUAL( \
90 git_repository_init_options
, GIT_REPOSITORY_INIT_OPTIONS_VERSION
, \
91 GIT_REPOSITORY_INIT_OPTIONS_INIT
, git_repository_init_init_options
);
94 CHECK_MACRO_FUNC_INIT_EQUAL( \
95 git_revert_opts
, GIT_REVERT_OPTS_VERSION
, \
96 GIT_REVERT_OPTS_INIT
, git_revert_init_opts
);
99 CHECK_MACRO_FUNC_INIT_EQUAL( \
100 git_status_options
, GIT_STATUS_OPTIONS_VERSION
, \
101 GIT_STATUS_OPTIONS_INIT
, git_status_init_options
);
104 CHECK_MACRO_FUNC_INIT_EQUAL( \
105 git_transport
, GIT_TRANSPORT_VERSION
, \
106 GIT_TRANSPORT_INIT
, git_transport_init
);
109 CHECK_MACRO_FUNC_INIT_EQUAL( \
110 git_config_backend
, GIT_CONFIG_BACKEND_VERSION
, \
111 GIT_CONFIG_BACKEND_INIT
, git_config_init_backend
);
114 CHECK_MACRO_FUNC_INIT_EQUAL( \
115 git_odb_backend
, GIT_ODB_BACKEND_VERSION
, \
116 GIT_ODB_BACKEND_INIT
, git_odb_init_backend
);
119 CHECK_MACRO_FUNC_INIT_EQUAL( \
120 git_refdb_backend
, GIT_REFDB_BACKEND_VERSION
, \
121 GIT_REFDB_BACKEND_INIT
, git_refdb_init_backend
);