NASA Logo
Ocean Color Science Software

ocssw V2022
alloc.c
Go to the documentation of this file.
1 
2 #include <allocate2d.h>
3 
4 #include <check.h>
5 #include <stdint.h>
6 #include <stdio.h>
7 #include <stdlib.h>
8 
9 START_TEST(allocate2d){
10  size_t w = 5, h = 10;
11  // NB the order of the for loops
12  char **t1 = allocate2d_char(h, w);
13  for (size_t i=0;i<h;i++){
14  for (size_t j=0;j<w;j++){
15  t1[i][j] = (i * w) + j;
16  }
17  }
18  for (size_t i=0;i<h;i++){
19  for (size_t j=0;j<w;j++){
20  ck_assert_int_eq(t1[i][j], (i * w) + j);
21  }
22  }
23  free2d_char(t1);
24 }
25 END_TEST
26 
27 Suite* stub_suite(void){
28  Suite *s = suite_create("Stub");
29 
30  TCase *tc_core = tcase_create("Core");
31  tcase_add_test(tc_core, allocate2d);
32  suite_add_tcase(s, tc_core);
33 
34  return s;
35 }
36 
37 int main(int argc, char **argv){
38  int number_failed;
39 
40  Suite *s = stub_suite();
41  SRunner *sr = srunner_create(s);
42 
43  srunner_run_all(sr, CK_VERBOSE);
44  number_failed = srunner_ntests_failed(sr);
45  srunner_free(sr);
46  return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
47 }
48 
#define EXIT_SUCCESS
Definition: GEO_basic.h:72
int j
Definition: decode_rs.h:73
END_TEST Suite * stub_suite(void)
Definition: alloc.c:27
float h[MODELMAX]
Definition: atrem_corl1.h:131
START_TEST(allocate2d)
Definition: alloc.c:9
int main(int argc, char **argv)
Definition: alloc.c:37
void free2d_char(char **p)
Free a two-dimensional array created by allocate2d_char.
Definition: allocate2d.c:30
Utility functions for allocating and freeing two-dimensional arrays of various types.
data_t s[NROOTS]
Definition: decode_rs.h:75
int i
Definition: decode_rs.h:71
char ** allocate2d_char(size_t h, size_t w)
Allocate a two-dimensional array of type char of a given size.
Definition: allocate2d.c:13