LCOV - code coverage report
Current view: top level - source4/lib/registry/tests - generic.c (source / functions) Hit Total Coverage
Test: coverage report for master 469b22b8 Lines: 61 70 87.1 %
Date: 2024-06-10 12:05:21 Functions: 10 10 100.0 %

          Line data    Source code
       1             : /*
       2             :    Unix SMB/CIFS implementation.
       3             : 
       4             :    local testing of registry library
       5             : 
       6             :    Copyright (C) Jelmer Vernooij 2005-2007
       7             : 
       8             :    This program is free software; you can redistribute it and/or modify
       9             :    it under the terms of the GNU General Public License as published by
      10             :    the Free Software Foundation; either version 3 of the License, or
      11             :    (at your option) any later version.
      12             : 
      13             :    This program is distributed in the hope that it will be useful,
      14             :    but WITHOUT ANY WARRANTY; without even the implied warranty of
      15             :    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      16             :    GNU General Public License for more details.
      17             : 
      18             :    You should have received a copy of the GNU General Public License
      19             :    along with this program.  If not, see <http://www.gnu.org/licenses/>.
      20             : */
      21             : 
      22             : #include "includes.h"
      23             : #include "lib/registry/registry.h"
      24             : #include "torture/torture.h"
      25             : #include "librpc/gen_ndr/winreg.h"
      26             : #include "param/param.h"
      27             : #include "lib/registry/tests/proto.h"
      28             : 
      29           1 : static bool test_str_regtype(struct torture_context *ctx)
      30             : {
      31           1 :         torture_assert_str_equal(ctx, str_regtype(0),
      32             :                                  "REG_NONE", "REG_NONE failed");
      33           1 :         torture_assert_str_equal(ctx, str_regtype(1),
      34             :                                  "REG_SZ", "REG_SZ failed");
      35           1 :         torture_assert_str_equal(ctx, str_regtype(2),
      36             :                                  "REG_EXPAND_SZ", "REG_EXPAND_SZ failed");
      37           1 :         torture_assert_str_equal(ctx, str_regtype(3),
      38             :                                  "REG_BINARY", "REG_BINARY failed");
      39           1 :         torture_assert_str_equal(ctx, str_regtype(4),
      40             :                                  "REG_DWORD", "REG_DWORD failed");
      41           1 :         torture_assert_str_equal(ctx, str_regtype(5),
      42             :                                  "REG_DWORD_BIG_ENDIAN", "REG_DWORD_BIG_ENDIAN failed");
      43           1 :         torture_assert_str_equal(ctx, str_regtype(6),
      44             :                                  "REG_LINK", "REG_LINK failed");
      45           1 :         torture_assert_str_equal(ctx, str_regtype(7),
      46             :                                  "REG_MULTI_SZ", "REG_MULTI_SZ failed");
      47           1 :         torture_assert_str_equal(ctx, str_regtype(8),
      48             :                                  "REG_RESOURCE_LIST", "REG_RESOURCE_LIST failed");
      49           1 :         torture_assert_str_equal(ctx, str_regtype(9),
      50             :                                  "REG_FULL_RESOURCE_DESCRIPTOR", "REG_FULL_RESOURCE_DESCRIPTOR failed");
      51           1 :         torture_assert_str_equal(ctx, str_regtype(10),
      52             :                                  "REG_RESOURCE_REQUIREMENTS_LIST", "REG_RESOURCE_REQUIREMENTS_LIST failed");
      53           1 :         torture_assert_str_equal(ctx, str_regtype(11),
      54             :                                  "REG_QWORD", "REG_QWORD failed");
      55             : 
      56           0 :         return true;
      57             : }
      58             : 
      59             : 
      60           1 : static bool test_reg_val_data_string_dword(struct torture_context *ctx)
      61             : {
      62           1 :         uint8_t d[] = { 0x20, 0x00, 0x00, 0x00 };
      63           1 :         DATA_BLOB db = { d, 4 };
      64           1 :         torture_assert_str_equal(ctx, "0x00000020",
      65             :                                  reg_val_data_string(ctx, REG_DWORD, db),
      66             :                                  "dword failed");
      67           0 :         return true;
      68             : }
      69             : 
      70           1 : static bool test_reg_val_data_string_dword_big_endian(struct torture_context *ctx)
      71             : {
      72           1 :         uint8_t d[] = { 0x20, 0x00, 0x00, 0x00 };
      73           1 :         DATA_BLOB db = { d, 4 };
      74           1 :         torture_assert_str_equal(ctx, "0x00000020",
      75             :                                  reg_val_data_string(ctx, REG_DWORD_BIG_ENDIAN, db),
      76             :                                  "dword failed");
      77           0 :         return true;
      78             : }
      79             : 
      80           1 : static bool test_reg_val_data_string_qword(struct torture_context *ctx)
      81             : {
      82           1 :         uint8_t d[] = { 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
      83           1 :         DATA_BLOB db = { d, 8 };
      84           1 :         torture_assert_str_equal(ctx, "0x0000000000000020",
      85             :                                  reg_val_data_string(ctx, REG_QWORD, db),
      86             :                                  "qword failed");
      87           0 :         return true;
      88             : }
      89             : 
      90           1 : static bool test_reg_val_data_string_sz(struct torture_context *ctx)
      91             : {
      92           1 :         DATA_BLOB db;
      93           1 :         convert_string_talloc(ctx, CH_UTF8, CH_UTF16,
      94             :                                           "bla", 3, (void **)&db.data, &db.length);
      95           1 :         torture_assert_str_equal(ctx, "bla",
      96             :                                  reg_val_data_string(ctx, REG_SZ, db),
      97             :                                  "sz failed");
      98           1 :         db.length = 4;
      99           1 :         torture_assert_str_equal(ctx, "bl",
     100             :                                  reg_val_data_string(ctx, REG_SZ, db),
     101             :                                  "sz failed");
     102           0 :         return true;
     103             : }
     104             : 
     105           1 : static bool test_reg_val_data_string_binary(struct torture_context *ctx)
     106             : {
     107           1 :         uint8_t x[] = { 0x1, 0x2, 0x3, 0x4 };
     108           1 :         DATA_BLOB db = { x, 4 };
     109           1 :         torture_assert_str_equal(ctx, "01020304",
     110             :                                  reg_val_data_string(ctx, REG_BINARY, db),
     111             :                                  "binary failed");
     112           0 :         return true;
     113             : }
     114             : 
     115             : 
     116           1 : static bool test_reg_val_data_string_empty(struct torture_context *ctx)
     117             : {
     118           1 :         DATA_BLOB db = { NULL, 0 };
     119           1 :         torture_assert_str_equal(ctx, "",
     120             :                                  reg_val_data_string(ctx, REG_BINARY, db),
     121             :                                  "empty failed");
     122           0 :         return true;
     123             : }
     124             : 
     125           1 : static bool test_reg_val_description(struct torture_context *ctx)
     126             : {
     127           1 :         DATA_BLOB data;
     128           1 :         convert_string_talloc(ctx, CH_UTF8, CH_UTF16,
     129             :                                             "stationary traveller",
     130             :                                             strlen("stationary traveller"),
     131             :                                             (void **)&data.data, &data.length);
     132           1 :         torture_assert_str_equal(ctx, "camel = REG_SZ : stationary traveller",
     133             :                                  reg_val_description(ctx, "camel", REG_SZ, data),
     134             :                                  "reg_val_description failed");
     135           0 :         return true;
     136             : }
     137             : 
     138             : 
     139           1 : static bool test_reg_val_description_nullname(struct torture_context *ctx)
     140             : {
     141           1 :         DATA_BLOB data;
     142           1 :         convert_string_talloc(ctx, CH_UTF8, CH_UTF16,
     143             :                                             "west berlin",
     144             :                                             strlen("west berlin"),
     145             :                                             (void **)&data.data, &data.length);
     146           1 :         torture_assert_str_equal(ctx, "<No Name> = REG_SZ : west berlin",
     147             :                                  reg_val_description(ctx, NULL, REG_SZ, data),
     148             :                                  "description with null name failed");
     149           0 :         return true;
     150             : }
     151             : 
     152        2363 : struct torture_suite *torture_registry(TALLOC_CTX *mem_ctx)
     153             : {
     154        2363 :         struct torture_suite *suite = torture_suite_create(mem_ctx, "registry");
     155        2363 :         torture_suite_add_simple_test(suite, "str_regtype",
     156             :                                       test_str_regtype);
     157        2363 :         torture_suite_add_simple_test(suite, "reg_val_data_string dword",
     158             :                                       test_reg_val_data_string_dword);
     159        2363 :         torture_suite_add_simple_test(suite, "reg_val_data_string dword_big_endian",
     160             :                                       test_reg_val_data_string_dword_big_endian);
     161        2363 :         torture_suite_add_simple_test(suite, "reg_val_data_string qword",
     162             :                                       test_reg_val_data_string_qword);
     163        2363 :         torture_suite_add_simple_test(suite, "reg_val_data_string sz",
     164             :                                       test_reg_val_data_string_sz);
     165        2363 :         torture_suite_add_simple_test(suite, "reg_val_data_string binary",
     166             :                                       test_reg_val_data_string_binary);
     167        2363 :         torture_suite_add_simple_test(suite, "reg_val_data_string empty",
     168             :                                       test_reg_val_data_string_empty);
     169        2363 :         torture_suite_add_simple_test(suite, "reg_val_description",
     170             :                                       test_reg_val_description);
     171        2363 :         torture_suite_add_simple_test(suite, "reg_val_description null",
     172             :                                       test_reg_val_description_nullname);
     173             : 
     174        2363 :         torture_suite_add_suite(suite, torture_registry_hive(suite));
     175        2363 :         torture_suite_add_suite(suite, torture_registry_registry(suite));
     176        2363 :         torture_suite_add_suite(suite, torture_registry_diff(suite));
     177             : 
     178        2363 :         return suite;
     179             : }

Generated by: LCOV version 1.14