Revision 1659 trunk/tests/gtests/test_df_file.cpp

test_df_file.cpp (revision 1659)
1 1
#include <gtest/gtest.h>
2 2
#include <fvar.hpp>
3
#include <new>
4
//using std::new;
5 3

  
4
extern "C"
5
{
6
  void test_ad_exit(const int exit_code);
7
}
8

  
6 9
class test_df_file:public ::testing::Test {};
7 10

  
8 11
TEST_F(test_df_file, signs)
......
33 36
  delete [] a;
34 37
  a = 0;
35 38
}
36
TEST_F(test_df_file, instance_INT_MAX)
39
TEST_F(test_df_file, constructor_size)
37 40
{
38
  ASSERT_NO_THROW(DF_FILE instance(INT_MAX));
41
  ASSERT_NO_THROW(DF_FILE df_file(INT_MAX));
39 42
}
40
/*
41
TEST_F(test_df_file, instance_INT_MAX_plus_1)
43
TEST_F(test_df_file, union_sizeof)
42 44
{
43
  ASSERT_NO_THROW(DF_FILE instance(INT_MAX + 1));
45
  DF_FILE df_file(INT_MAX);
46
  ASSERT_EQ(sizeof(df_file.fourb), sizeof(df_file.offset));
44 47
}
48
TEST_F(test_df_file, constructor_INT_MAX_plus_1)
49
{
50
  ad_exit=&test_ad_exit;
51
  ASSERT_ANY_THROW(
52
    DF_FILE df_file(INT_MAX + 1)
53
  );
54
}
45 55
TEST_F(test_df_file, allocate_INT_MAX_plus_1)
46 56
{
47 57
  ASSERT_LT(INT_MAX, LONG_MAX);
......
60 70
  }
61 71
  FAIL();
62 72
}
63
*/
64 73
TEST_F(test_df_file, write_read_int)
65 74
{
66
  DF_FILE buffer(sizeof(int));
75
  size_t sizeofint = sizeof(int);
76
  DF_FILE buffer(sizeofint);
77
  ASSERT_EQ(0, buffer.offset);
78
  ASSERT_EQ(0, buffer.toffset);
79

  
80
  gradient_structure::no_derivatives = 0;
81

  
67 82
  const int expected = __LINE__;
68 83
  buffer.fwrite(expected);
84
  ASSERT_EQ(sizeofint, buffer.offset);
85
  ASSERT_EQ(sizeofint, buffer.toffset);
86

  
69 87
  int integer = 0;
70 88
  buffer.fread(integer);
71 89
  ASSERT_EQ(expected, integer);
72 90
}
91
TEST_F(test_df_file, write_read_int_asvoidpointer)
92
{
93
  size_t sizeofint = sizeof(int);
94
  DF_FILE buffer(sizeofint);
95
  ASSERT_EQ(0, buffer.offset);
96
  ASSERT_EQ(0, buffer.toffset);
97

  
98
  gradient_structure::no_derivatives = 0;
99

  
100
  const int expected = __LINE__;
101
  buffer.fwrite(&expected, sizeofint);
102

  
103
  ASSERT_EQ(sizeofint, buffer.offset);
104
  ASSERT_EQ(sizeofint, buffer.toffset);
105

  
106
  int integer = 0;
107
  buffer.fread(&integer, sizeofint);
108
  ASSERT_EQ(expected, integer);
109
}
110
TEST_F(test_df_file, write_read_double)
111
{
112
  const size_t us = sizeof(unsigned int) + 2;
113
  size_t sizeofdouble = sizeof(double);
114
  DF_FILE buffer(sizeofdouble + us);
115
  ASSERT_EQ(0, buffer.offset);
116
  ASSERT_EQ(0, buffer.toffset);
117

  
118
  gradient_structure::no_derivatives = 0;
119

  
120
  const double expected = 11.34567;
121
  buffer.fwrite(expected);
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff