GnuCash  5.6-150-g038405b370+
gmock-qofbook.h
1 #ifndef GMOCK_QOFBOOK_H
2 #define GMOCK_QOFBOOK_H
3 
4 #include <gmock/gmock.h>
5 
6 #include <qofbook.h>
7 #include <qofbook-p.h>
8 #include <Split.h>
9 
10 #include "gmock-gobject.h"
11 
12 
13 GType qof_mockbook_get_type(void);
14 
15 #define QOF_TYPE_MOCKBOOK (qof_mockbook_get_type ())
16 #define QOF_IS_MOCKBOOK(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), QOF_TYPE_MOCKBOOK))
17 
18 
19 // mock up for QofBook
20 class QofMockBook : public QofBook
21 {
22 public:
23  QofMockBook()
24  {
25  hash_of_collections = nullptr;
26  data_tables = nullptr;
27  data_table_finalizers = nullptr;
28 
29  book_open = 'n';
30  read_only = TRUE;
31  session_dirty = FALSE;
32 
33  version = 0;
34 
35  cached_num_field_source_isvalid = FALSE;
36  cached_num_days_autoreadonly_isvalid = FALSE;
37  }
38  void* operator new(size_t size)
39  {
40  return mock_g_object_new (QOF_TYPE_MOCKBOOK, NULL, size);
41  }
42 
43  // define separate free() function since destructor is protected
44  void free()
45  {
46  delete this;
47  }
48  void operator delete(void* book, size_t size)
49  {
50  mock_g_object_unref(book, size);
51  }
52 
53  MOCK_METHOD0(malloc_split, Split *());
54  MOCK_CONST_METHOD0(use_split_action_for_num_field, gboolean());
55 
56 protected:
57  // Protect destructor to avoid MockQofBook objects to be created on stack. MockQofBook
58  // objects can only be dynamically created, since they are derived from GObject.
59  ~QofMockBook() {}
60 };
61 
62 
63 // type conversion functions
64 static inline QofMockBook*
65 qof_mockbook (QofBook *book)
66 {
67  if (QOF_IS_MOCKBOOK(book))
68  return static_cast<QofMockBook*>(book);
69  ADD_FAILURE() << "Expected 'book' to be of type 'QofMockBook'";
70  return nullptr;
71 }
72 
73 static inline const QofMockBook*
74 qof_mockbook (const QofBook *book)
75 {
76  if (QOF_IS_MOCKBOOK(book))
77  return static_cast<const QofMockBook*>(book);
78  ADD_FAILURE() << "Expected 'book' to be of type 'QofMockBook'";
79  return nullptr;
80 }
81 
82 
83 #endif
API for Transactions and Splits (journal entries)
Encapsulate all the information about a dataset.