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: 3b461aa. Current time (UTC): 2024-01-25T16:04:32Z Lines: 94 94 100.0 %
Date: 2024-01-25 16:05:28 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_NOT_IMPLEMENTED) ;
      83           1 :     printf ("\nmsg: %s\n", msg) ;
      84             : 
      85           1 :     TEST_CHECK (LAGraph_NameOfType (NULL, NULL, msg) == GrB_NULL_POINTER) ;
      86           1 :     printf ("\nmsg: %s\n", msg) ;
      87             : 
      88           1 :     TEST_CHECK (LAGraph_NameOfType (name, NULL, msg) == GrB_NULL_POINTER) ;
      89           1 :     printf ("msg: %s\n", msg) ;
      90             : 
      91           1 :     TEST_CHECK (LAGraph_NameOfType (NULL, GrB_BOOL, msg) == GrB_NULL_POINTER) ;
      92           1 :     printf ("msg: %s\n", msg) ;
      93             : 
      94           1 :     GrB_free (&s) ;
      95           1 :     GrB_free (&type) ;
      96           1 :     OK (LAGraph_Finalize (msg)) ;
      97           1 : }
      98             : 
      99             : //------------------------------------------------------------------------------
     100             : // test_TypeSize :  test LAGraph_SizeOfType
     101             : //------------------------------------------------------------------------------
     102             : 
     103           1 : void test_TypeSize (void)
     104             : {
     105           1 :     OK (LAGraph_Init (msg)) ;
     106             :     size_t size ;
     107             : 
     108           1 :     size = 0 ;
     109           1 :     OK (LAGraph_SizeOfType  (&size, GrB_BOOL, msg)) ;
     110           1 :     TEST_CHECK (size == sizeof (bool)) ;
     111             : 
     112           1 :     size = 0 ;
     113           1 :     OK (LAGraph_SizeOfType  (&size, GrB_INT8, msg)) ;
     114           1 :     TEST_CHECK (size == sizeof (int8_t)) ;
     115             : 
     116           1 :     size = 0 ;
     117           1 :     OK (LAGraph_SizeOfType  (&size, GrB_INT16, msg)) ;
     118           1 :     TEST_CHECK (size == sizeof (int16_t)) ;
     119             : 
     120           1 :     size = 0 ;
     121           1 :     OK (LAGraph_SizeOfType  (&size, GrB_INT32, msg)) ;
     122           1 :     TEST_CHECK (size == sizeof (int32_t)) ;
     123             : 
     124           1 :     size = 0 ;
     125           1 :     OK (LAGraph_SizeOfType  (&size, GrB_INT64, msg)) ;
     126           1 :     TEST_CHECK (size == sizeof (int64_t)) ;
     127             : 
     128           1 :     size = 0 ;
     129           1 :     OK (LAGraph_SizeOfType  (&size, GrB_UINT8, msg)) ;
     130           1 :     TEST_CHECK (size == sizeof (uint8_t)) ;
     131             : 
     132           1 :     size = 0 ;
     133           1 :     OK (LAGraph_SizeOfType  (&size, GrB_UINT16, msg)) ;
     134           1 :     TEST_CHECK (size == sizeof (uint16_t)) ;
     135             : 
     136           1 :     size = 0 ;
     137           1 :     OK (LAGraph_SizeOfType  (&size, GrB_UINT32, msg)) ;
     138           1 :     TEST_CHECK (size == sizeof (uint32_t)) ;
     139             : 
     140           1 :     size = 0 ;
     141           1 :     OK (LAGraph_SizeOfType  (&size, GrB_UINT64, msg)) ;
     142           1 :     TEST_CHECK (size == sizeof (uint64_t)) ;
     143             : 
     144           1 :     size = 0 ;
     145           1 :     OK (LAGraph_SizeOfType  (&size, GrB_FP32, msg)) ;
     146           1 :     TEST_CHECK (size == sizeof (float)) ;
     147             : 
     148           1 :     size = 0 ;
     149           1 :     OK (LAGraph_SizeOfType  (&size, GrB_FP64, msg)) ;
     150           1 :     TEST_CHECK (size == sizeof (double)) ;
     151             : 
     152           1 :     size = 0 ;
     153           1 :     OK (GrB_Type_new (&type, sizeof (myint))) ;
     154           1 :     int result = LAGraph_SizeOfType (&size, type, msg) ;
     155             :     #if LAGRAPH_SUITESPARSE
     156           1 :     printf ("\nSuiteSparse knows the type size: [%g]\n", (double) size) ;
     157           1 :     TEST_CHECK (result == GrB_SUCCESS) ;
     158           1 :     TEST_CHECK (size == sizeof (myint)) ;
     159             :     #else
     160             :     TEST_CHECK (result == GrB_NOT_IMPLEMENTED) ;
     161             :     printf ("\nmsg: %s\n", msg) ;
     162             :     #endif
     163             : 
     164           1 :     TEST_CHECK (LAGraph_SizeOfType (NULL, NULL, msg) == GrB_NULL_POINTER) ;
     165           1 :     printf ("\nmsg: %s\n", msg) ;
     166             : 
     167           1 :     TEST_CHECK (LAGraph_SizeOfType (&size, NULL, msg) == GrB_NULL_POINTER) ;
     168           1 :     printf ("msg: %s\n", msg) ;
     169             : 
     170           1 :     TEST_CHECK (LAGraph_SizeOfType (NULL, GrB_BOOL, msg) == GrB_NULL_POINTER) ;
     171           1 :     printf ("msg: %s\n", msg) ;
     172             : 
     173           1 :     GrB_free (&type) ;
     174           1 :     OK (LAGraph_Finalize (msg)) ;
     175           1 : }
     176             : 
     177             : //-----------------------------------------------------------------------------
     178             : // TEST_LIST: the list of tasks for this entire test
     179             : //-----------------------------------------------------------------------------
     180             : 
     181             : TEST_LIST =
     182             : {
     183             :     { "TypeName", test_TypeName  },
     184             :     { "TypeSize", test_TypeSize  },
     185             :     // no brutal test needed
     186             :     { NULL, NULL }
     187             : } ;

Generated by: LCOV version 1.14