/simpletypesystem/trunk

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/simpletypesystem/trunk

« back to all changes in this revision

Viewing changes to tests/error.c

  • Committer: Gustav Hartvigsson
  • Date: 2015-04-08 18:25:07 UTC
  • Revision ID: gustav.hartvigsson@gmail.com-20150408182507-094jw13yhmi3bhfu
* Added "check" target for testing.
* Changed SRC to SSTS_SRC for future proofing.
* Removed a few "_" from before some struct names. It is not needed.
* Re-wrote how s_object_to_string () works on SError's. Should be faster now, but less safe...
  * To make this work I added SErrorTypeName string array. (Need to surpress the errer it creats).
* Re-orderd SErrorType enum.
* Use s_string_new_fmt () the default method for s_object_to_string ().
* Changed to strdup in some functions in utils.c.
* Added s_current_time () function to get an ISO time string.
* Added some more documentation to utils.h
* !DEBUG -> DEBUG in utils.h
* Added more tests to the test suite.
* Re-Wrote test_macros.h to display time, making it a lil' bit nicer to look at.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#include "SimpleTypeSystem.h"
2
 
 
3
 
int main (char ** argc, int argv) {
4
 
  
5
 
  SError * e = s_error_new (S_ERROR_NONE, "Nothing at all...");
6
 
  char * s = s_base_object_to_string (e);
7
 
  
8
 
  s_print (s);
9
 
  s_print ("\n");
10
 
 
 
2
#include "error.h"
 
3
#include "test_macros.h"
 
4
 
 
5
int test_error () {
 
6
  setup_unit ();
 
7
  
 
8
  SError * e = NULL;
 
9
  char * s = NULL;
 
10
  
 
11
  char * expected_string = NULL;
 
12
  
 
13
  e = s_error_new (S_ERROR_NONE, "Nothing at all...");
 
14
  
 
15
  test_case (e != NULL, "SError object is not NULL.");
 
16
  
 
17
  expected_string = s_string_new ("Error: NONE, Message: Nothing at all...");
 
18
  
 
19
  s = s_object_to_string (S_OBJECT(e));
 
20
  
 
21
  test_case (strcmp (expected_string, s) == 0, "Expected string matches the result.")
 
22
  
 
23
  s_print ("%s\n", s);
 
24
  
11
25
  free (s);
12
 
 
13
 
  s_base_object_unref (e);
 
26
  free (expected_string);
 
27
  
 
28
  test_case (s_object_unref (S_OBJECT(e)) == 0,
 
29
             "SError's refcount is 0 on unref.");
14
30
  
15
31
  e = s_error_new (S_ERROR_INPUT_OUTPUT, "Generic I/O Error...");
16
 
  s = s_base_object_to_string (e);
 
32
  s = s_object_to_string (S_OBJECT(e));
17
33
  
18
 
  s_print (s);
19
 
  s_print ("\n");
 
34
  s_print ("%s\n", s);
20
35
  
21
36
  free (s);
22
37
  
23
 
  s_base_object_unref (e);
 
38
  s_object_unref (S_OBJECT(e));
24
39
  
25
40
  e = s_error_new (S_ERROR_OVERFLOW, "A Generic overflow error...");
26
 
  s = s_base_object_to_string (e);
 
41
  s = s_object_to_string (S_OBJECT(e));
27
42
  
28
 
  s_print (s);
29
 
  s_print ("\n");
 
43
  s_print ("%s\n", s);
30
44
  
31
45
  free (s);
32
46
  
33
 
  s_base_object_unref (e);
 
47
  s_object_unref (S_OBJECT(e));
34
48
  
35
49
  e = s_error_new (S_ERROR_OTHER, "Some unknowned error type...");
36
 
  s = s_base_object_to_string (e);
 
50
  s = s_object_to_string (S_OBJECT(e));
37
51
  
38
 
  s_print (s);
39
 
  s_print ("\n");
 
52
  s_print ("%s\n", s);
40
53
  
41
54
  free (s);
42
55
  
43
 
  s_base_object_unref (e);
 
56
  s_object_unref (S_OBJECT(e));
44
57
  
45
58
  
46
59
  e = s_error_new (S_ERROR_NULL, "A NULL error...");
47
 
  s = s_base_object_to_string (e);
 
60
  s = s_object_to_string (S_OBJECT(e));
48
61
  
49
 
  s_print (s);
50
 
  s_print ("\n");
 
62
  s_print ("%s\n", s);
51
63
  
52
64
  free (s);
53
65
  
54
 
  s_base_object_unref (e);
55
 
 
56
 
  return 0;
 
66
  s_object_unref (S_OBJECT(e));
 
67
  end_unit ();
57
68
}