"Fossies" - the Fresh Open Source Software Archive

Member "cfengine-3.15.4/tests/unit/new_packages_promise_test.c" (7 Jun 2021, 2715 Bytes) of package /linux/misc/cfengine-3.15.4.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. See also the latest Fossies "Diffs" side-by-side code changes report for "new_packages_promise_test.c": 3.15.3_vs_3.15.4.

    1 #include <test.h>
    2 
    3 #include <eval_context.h>
    4 #include <string_lib.h>
    5 
    6 static inline
    7 PackageModuleBody *make_mock_package_module(const char *name, int updates_ifel, int installed_ifel, Rlist *options)
    8 {
    9     PackageModuleBody *pm = xcalloc(1, sizeof(PackageModuleBody));
   10     pm->name = SafeStringDuplicate(name);
   11     pm->installed_ifelapsed = installed_ifel;
   12     pm->updates_ifelapsed = updates_ifel;
   13     pm->options = RlistCopy(options);
   14     return pm;
   15 }
   16 
   17 static void test_add_module_to_context()
   18 {
   19     EvalContext *ctx = EvalContextNew();
   20 
   21     PackageModuleBody *pm = make_mock_package_module("apt_get", 120, 240, NULL);
   22     AddPackageModuleToContext(ctx, pm);
   23 
   24     PackageModuleBody *pm2 = make_mock_package_module("yum", 220, 440, NULL);
   25     AddPackageModuleToContext(ctx, pm2);
   26 
   27     PackagePromiseContext *pp_ctx = GetPackagePromiseContext(ctx);
   28 
   29     assert_true(pp_ctx != NULL);
   30     assert_int_equal(2, SeqLength(pp_ctx->package_modules_bodies));
   31 
   32     PackageModuleBody *yum = GetPackageModuleFromContext(ctx, "yum");
   33     assert_true(yum != NULL);
   34     assert_int_equal(220, yum->updates_ifelapsed);
   35     assert_int_equal(440, yum->installed_ifelapsed);
   36 
   37     /* make sure that adding body with the same name will not make set larger */
   38     PackageModuleBody *pm3 = make_mock_package_module("yum", 330, 550, NULL);
   39     AddPackageModuleToContext(ctx, pm3);
   40 
   41     assert_int_equal(2, SeqLength(pp_ctx->package_modules_bodies));
   42 
   43     /* check if parameters are updated */
   44     yum = GetPackageModuleFromContext(ctx, "yum");
   45     assert_int_equal(330, yum->updates_ifelapsed);
   46     assert_int_equal(550, yum->installed_ifelapsed);
   47 
   48     EvalContextDestroy(ctx);
   49 }
   50 
   51 static void test_default_package_module_settings()
   52 {
   53     EvalContext *ctx = EvalContextNew();
   54 
   55     PackageModuleBody *pm = make_mock_package_module("apt_get", 120, 240, NULL);
   56     AddPackageModuleToContext(ctx, pm);
   57 
   58     PackageModuleBody *pm2 = make_mock_package_module("yum", 220, 440, NULL);
   59     AddPackageModuleToContext(ctx, pm2);
   60 
   61     PackageModuleBody *pm3 = make_mock_package_module("yum_2", 220, 440, NULL);
   62     AddPackageModuleToContext(ctx, pm3);
   63 
   64     AddDefaultPackageModuleToContext(ctx, "apt_get");
   65     PackageModuleBody *def_pm = GetDefaultPackageModuleFromContext(ctx);
   66     assert_string_equal("apt_get", def_pm->name);
   67 
   68     AddDefaultPackageModuleToContext(ctx, "yum");
   69     def_pm = GetDefaultPackageModuleFromContext(ctx);
   70     assert_string_equal("yum", def_pm->name);
   71 
   72     EvalContextDestroy(ctx);
   73 }
   74 
   75 
   76 int main()
   77 {
   78     PRINT_TEST_BANNER();
   79 
   80     const UnitTest tests[] =
   81     {
   82         unit_test(test_default_package_module_settings),
   83         unit_test(test_add_module_to_context),
   84     };
   85 
   86     int ret = run_tests(tests);
   87 
   88     return ret;
   89 }