LCOV - code coverage report
Current view: top level - src/test - test_Type.c (source / functions) Hit Total Coverage
Test: LAGraph code coverage report. Commit id: 7b9d2ee. Current time (UTC): 2025-06-03T21:57:17Z Lines: 102 102 100.0 %
Date: 2025-06-03 22:02:40 Functions: 2 2 100.0 %

          Line data    Source code
       1             : //------------------------------------------------------------------------------
       2             : // LAGraph/src/test/test_Type.c:  test LAGraph_*Type* methods
       3             : //------------------------------------------------------------------------------
       4             : 
       5             : // LAGraph, (c) 2019-2022 by The LAGraph Contributors, All Rights Reserved.
       6             : // SPDX-License-Identifier: BSD-2-Clause
       7             : //
       8             : // For additional details (including references to third party source code and
       9             : // other files) see the LICENSE file or contact permission@sei.cmu.edu. See
      10             : // Contributors.txt for a full list of contributors. Created, in part, with
      11             : // funding and support from the U.S. Government (see Acknowledgments.txt file).
      12             : // DM22-0790
      13             : 
      14             : // Contributed by Timothy A. Davis, Texas A&M University
      15             : 
      16             : //------------------------------------------------------------------------------
      17             : 
      18             : #include "LAGraph_test.h"
      19             : 
      20             : //------------------------------------------------------------------------------
      21             : // global variables
      22             : //------------------------------------------------------------------------------
      23             : 
      24             : GrB_Type type = NULL ;
      25             : char name [LAGRAPH_MAX_NAME_LEN] ;
      26             : char msg [LAGRAPH_MSG_LEN] ;
      27             : GrB_Scalar s = NULL ;
      28             : 
      29             : typedef int myint ;
      30             : 
      31             : //------------------------------------------------------------------------------
      32             : // test_TypeName :  test LAGraph_NameOfType
      33             : //------------------------------------------------------------------------------
      34             : 
      35           1 : void test_TypeName  (void)
      36             : {
      37           1 :     OK (LAGraph_Init (msg)) ;
      38             : 
      39           1 :     OK (LAGraph_NameOfType  (name, GrB_BOOL, msg)) ;
      40           1 :     OK (strcmp (name, "bool")) ;
      41             : 
      42           1 :     OK (LAGraph_NameOfType  (name, GrB_INT8, msg)) ;
      43           1 :     OK (strcmp (name, "int8_t")) ;
      44             : 
      45           1 :     OK (LAGraph_NameOfType  (name, GrB_INT16, msg)) ;
      46           1 :     OK (strcmp (name, "int16_t")) ;
      47             : 
      48           1 :     OK (LAGraph_NameOfType  (name, GrB_INT32, msg)) ;
      49           1 :     OK (strcmp (name, "int32_t")) ;
      50             : 
      51           1 :     OK (LAGraph_NameOfType  (name, GrB_INT64, msg)) ;
      52           1 :     OK (strcmp (name, "int64_t")) ;
      53             : 
      54           1 :     OK (LAGraph_NameOfType  (name, GrB_UINT8, msg)) ;
      55           1 :     OK (strcmp (name, "uint8_t")) ;
      56             : 
      57           1 :     OK (LAGraph_NameOfType  (name, GrB_UINT16, msg)) ;
      58           1 :     OK (strcmp (name, "uint16_t")) ;
      59             : 
      60           1 :     OK (LAGraph_NameOfType  (name, GrB_UINT32, msg)) ;
      61           1 :     OK (strcmp (name, "uint32_t")) ;
      62             : 
      63           1 :     OK (LAGraph_NameOfType  (name, GrB_UINT64, msg)) ;
      64           1 :     OK (strcmp (name, "uint64_t")) ;
      65             : 
      66           1 :     OK (LAGraph_NameOfType  (name, GrB_FP32, msg)) ;
      67           1 :     OK (strcmp (name, "float")) ;
      68             : 
      69           1 :     OK (LAGraph_NameOfType  (name, GrB_FP64, msg)) ;
      70           1 :     OK (strcmp (name, "double")) ;
      71             : 
      72             :     char typename [LAGRAPH_MAX_NAME_LEN] ;
      73           1 :     OK (GrB_Scalar_new (&s, GrB_INT32)) ;
      74           1 :     OK (LAGraph_Scalar_TypeName (name, s, msg)) ;
      75           1 :     OK (strcmp (name, "int32_t")) ;
      76           1 :     TEST_CHECK (LAGraph_Scalar_TypeName (NULL, s, msg) == GrB_NULL_POINTER) ;
      77           1 :     TEST_CHECK (LAGraph_Scalar_TypeName (name, NULL, msg) == GrB_NULL_POINTER) ;
      78             : 
      79           1 :     name [0] = '\0' ;
      80           1 :     OK (GrB_Type_new (&type, sizeof (myint))) ;
      81           1 :     int result = LAGraph_NameOfType (name, type, msg) ;
      82           1 :     TEST_CHECK (result == GrB_SUCCESS) ;
      83           1 :     printf ("\ntype name not yet set: [%s]\n", name) ;
      84           1 :     OK (strcmp (name, "")) ;
      85             : 
      86           1 :     OK (GrB_set (type, "myinteger", GrB_NAME)) ;
      87           1 :     result = LAGraph_NameOfType (name, type, msg) ;
      88           1 :     TEST_CHECK (result == GrB_SUCCESS) ;
      89           1 :     printf ("\ntype name: [%s]\n", name) ;
      90           1 :     OK (strcmp (name, "myinteger")) ;
      91             : 
      92           1 :     printf ("\nthree expected error messages:\n") ;
      93           1 :     TEST_CHECK (LAGraph_NameOfType (NULL, NULL, msg) == GrB_NULL_POINTER) ;
      94           1 :     printf ("msg: %s\n", msg) ;
      95             : 
      96           1 :     TEST_CHECK (LAGraph_NameOfType (name, NULL, msg) == GrB_NULL_POINTER) ;
      97           1 :     printf ("msg: %s\n", msg) ;
      98             : 
      99           1 :     TEST_CHECK (LAGraph_NameOfType (NULL, GrB_BOOL, msg) == GrB_NULL_POINTER) ;
     100           1 :     printf ("msg: %s\n", msg) ;
     101             : 
     102           1 :     GrB_free (&s) ;
     103           1 :     GrB_free (&type) ;
     104           1 :     OK (LAGraph_Finalize (msg)) ;
     105           1 : }
     106             : 
     107             : //------------------------------------------------------------------------------
     108             : // test_TypeSize :  test LAGraph_SizeOfType
     109             : //------------------------------------------------------------------------------
     110             : 
     111           1 : void test_TypeSize (void)
     112             : {
     113           1 :     OK (LAGraph_Init (msg)) ;
     114             :     size_t size ;
     115             : 
     116           1 :     size = 0 ;
     117           1 :     OK (LAGraph_SizeOfType  (&size, GrB_BOOL, msg)) ;
     118           1 :     TEST_CHECK (size == sizeof (bool)) ;
     119             : 
     120           1 :     size = 0 ;
     121           1 :     OK (LAGraph_SizeOfType  (&size, GrB_INT8, msg)) ;
     122           1 :     TEST_CHECK (size == sizeof (int8_t)) ;
     123             : 
     124           1 :     size = 0 ;
     125           1 :     OK (LAGraph_SizeOfType  (&size, GrB_INT16, msg)) ;
     126           1 :     TEST_CHECK (size == sizeof (int16_t)) ;
     127             : 
     128           1 :     size = 0 ;
     129           1 :     OK (LAGraph_SizeOfType  (&size, GrB_INT32, msg)) ;
     130           1 :     TEST_CHECK (size == sizeof (int32_t)) ;
     131             : 
     132           1 :     size = 0 ;
     133           1 :     OK (LAGraph_SizeOfType  (&size, GrB_INT64, msg)) ;
     134           1 :     TEST_CHECK (size == sizeof (int64_t)) ;
     135             : 
     136           1 :     size = 0 ;
     137           1 :     OK (LAGraph_SizeOfType  (&size, GrB_UINT8, msg)) ;
     138           1 :     TEST_CHECK (size == sizeof (uint8_t)) ;
     139             : 
     140           1 :     size = 0 ;
     141           1 :     OK (LAGraph_SizeOfType  (&size, GrB_UINT16, msg)) ;
     142           1 :     TEST_CHECK (size == sizeof (uint16_t)) ;
     143             : 
     144           1 :     size = 0 ;
     145           1 :     OK (LAGraph_SizeOfType  (&size, GrB_UINT32, msg)) ;
     146           1 :     TEST_CHECK (size == sizeof (uint32_t)) ;
     147             : 
     148           1 :     size = 0 ;
     149           1 :     OK (LAGraph_SizeOfType  (&size, GrB_UINT64, msg)) ;
     150           1 :     TEST_CHECK (size == sizeof (uint64_t)) ;
     151             : 
     152           1 :     size = 0 ;
     153           1 :     OK (LAGraph_SizeOfType  (&size, GrB_FP32, msg)) ;
     154           1 :     TEST_CHECK (size == sizeof (float)) ;
     155             : 
     156           1 :     size = 0 ;
     157           1 :     OK (LAGraph_SizeOfType  (&size, GrB_FP64, msg)) ;
     158           1 :     TEST_CHECK (size == sizeof (double)) ;
     159             : 
     160           1 :     size = 0 ;
     161           1 :     OK (GrB_Type_new (&type, sizeof (myint))) ;
     162           1 :     int result = LAGraph_SizeOfType (&size, type, msg) ;
     163           1 :     printf ("\ntype size: [%g]\n", (double) size) ;
     164           1 :     TEST_CHECK (result == GrB_SUCCESS) ;
     165           1 :     TEST_CHECK (size == sizeof (myint)) ;
     166             : 
     167           1 :     printf ("\nthree expected error messages:\n") ;
     168           1 :     TEST_CHECK (LAGraph_SizeOfType (NULL, NULL, msg) == GrB_NULL_POINTER) ;
     169           1 :     printf ("msg: %s\n", msg) ;
     170             : 
     171           1 :     TEST_CHECK (LAGraph_SizeOfType (&size, NULL, msg) == GrB_NULL_POINTER) ;
     172           1 :     printf ("msg: %s\n", msg) ;
     173             : 
     174           1 :     TEST_CHECK (LAGraph_SizeOfType (NULL, GrB_BOOL, msg) == GrB_NULL_POINTER) ;
     175           1 :     printf ("msg: %s\n", msg) ;
     176             : 
     177           1 :     GrB_free (&type) ;
     178           1 :     OK (LAGraph_Finalize (msg)) ;
     179           1 : }
     180             : 
     181             : //-----------------------------------------------------------------------------
     182             : // TEST_LIST: the list of tasks for this entire test
     183             : //-----------------------------------------------------------------------------
     184             : 
     185             : TEST_LIST =
     186             : {
     187             :     { "TypeName", test_TypeName  },
     188             :     { "TypeSize", test_TypeSize  },
     189             :     // no brutal test needed
     190             :     { NULL, NULL }
     191             : } ;

Generated by: LCOV version 1.14