LCOV - code coverage report
Current view: top level - source4/torture/ndr - charset.c (source / functions) Hit Total Coverage
Test: coverage report for master 2f515e9b Lines: 23 25 92.0 %
Date: 2024-04-21 15:09:00 Functions: 3 3 100.0 %

          Line data    Source code
       1             : /*
       2             :    Unix SMB/CIFS implementation.
       3             :    test suite for charset ndr operations
       4             : 
       5             :    Copyright (C) Guenther Deschner 2017
       6             : 
       7             :    This program is free software; you can redistribute it and/or modify
       8             :    it under the terms of the GNU General Public License as published by
       9             :    the Free Software Foundation; either version 3 of the License, or
      10             :    (at your option) any later version.
      11             : 
      12             :    This program is distributed in the hope that it will be useful,
      13             :    but WITHOUT ANY WARRANTY; without even the implied warranty of
      14             :    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      15             :    GNU General Public License for more details.
      16             : 
      17             :    You should have received a copy of the GNU General Public License
      18             :    along with this program.  If not, see <http://www.gnu.org/licenses/>.
      19             : */
      20             : 
      21             : #include "includes.h"
      22             : #include "torture/ndr/ndr.h"
      23             : #include "torture/ndr/proto.h"
      24             : 
      25           2 : static bool test_ndr_push_charset(struct torture_context *tctx)
      26             : {
      27           2 :         const char *strs[] = {
      28             :                 NULL,
      29             :                 "",
      30             :                 "test"
      31             :         };
      32           2 :         int i;
      33             : 
      34           2 :         struct ndr_push *ndr;
      35             : 
      36           2 :         ndr = talloc_zero(tctx, struct ndr_push);
      37             : 
      38          10 :         for (i = 0; i < ARRAY_SIZE(strs); i++) {
      39             : 
      40           6 :                 enum ndr_err_code expected_ndr_err = NDR_ERR_SUCCESS;
      41             : 
      42           6 :                 if (strs[i] == NULL) {
      43           2 :                         expected_ndr_err = NDR_ERR_INVALID_POINTER;
      44             :                 }
      45             : 
      46           6 :                 torture_assert_ndr_err_equal(tctx,
      47             :                         ndr_push_charset(ndr, NDR_SCALARS, strs[i], 256, 2, CH_UTF16LE),
      48             :                         expected_ndr_err,
      49             :                         "failed to push charset");
      50             :         }
      51             : 
      52           0 :         return true;
      53             : }
      54             : 
      55           2 : static bool test_ndr_push_charset_to_null(struct torture_context *tctx)
      56             : {
      57           2 :         const char *strs[] = {
      58             :                 NULL,
      59             :                 "",
      60             :                 "test"
      61             :         };
      62           2 :         int i;
      63             : 
      64           2 :         struct ndr_push *ndr;
      65             : 
      66           2 :         ndr = talloc_zero(tctx, struct ndr_push);
      67             : 
      68             : 
      69          10 :         for (i = 0; i < ARRAY_SIZE(strs); i++) {
      70             : 
      71           6 :                 torture_assert_ndr_success(tctx,
      72             :                         ndr_push_charset_to_null(ndr, NDR_SCALARS, strs[i], 256, 2, CH_UTF16LE),
      73             :                         "failed to push charset to null");
      74             :         }
      75             : 
      76           0 :         return true;
      77             : }
      78             : 
      79             : 
      80        2354 : struct torture_suite *ndr_charset_suite(TALLOC_CTX *ctx)
      81             : {
      82        2354 :         struct torture_suite *suite = torture_suite_create(ctx, "charset");
      83             : 
      84        2354 :         suite->description = talloc_strdup(suite, "NDR - charset focused push/pull tests");
      85             : 
      86        2354 :         torture_suite_add_simple_test(suite, "push", test_ndr_push_charset);
      87        2354 :         torture_suite_add_simple_test(suite, "push_to_null", test_ndr_push_charset_to_null);
      88             : 
      89        2354 :         return suite;
      90             : }
      91             : 

Generated by: LCOV version 1.14