~ubuntu-branches/ubuntu/trusty/dee/trusty

« back to all changes in this revision

Viewing changes to tests/test-transaction.c

  • Committer: Package Import Robot
  • Author(s): Ubuntu daily release
  • Date: 2013-09-04 02:32:11 UTC
  • mto: This revision was merged to the branch mainline in revision 36.
  • Revision ID: package-import@ubuntu.com-20130904023211-nkxz3f29x5ezjmqt
Tags: upstream-1.2.6+13.10.20130904
ImportĀ upstreamĀ versionĀ 1.2.6+13.10.20130904

Show diffs side-by-side

added added

removed removed

Lines of Context:
45
45
}
46
46
 
47
47
static void
 
48
setup_basic_types (Fixture *fix, gconstpointer data)
 
49
{
 
50
  fix->model = dee_sequence_model_new ();
 
51
  dee_model_set_schema (fix->model, "b", "y", "i", "u", "x", "t", "d", "s", NULL);
 
52
 
 
53
  /* The txn must be created during the tests because we need to verify how
 
54
   * it works when constructed on top of various states of the fix->model */
 
55
}
 
56
 
 
57
static void
48
58
setup_proxy (Fixture *fix, gconstpointer data)
49
59
{
50
60
  DeeModel *backend = dee_sequence_model_new ();
85
95
  g_assert_cmpint (dee_model_get_n_columns (fix->txn), == , 2);
86
96
  g_assert_cmpstr (dee_model_get_column_schema (fix->txn, 0), ==, "s");
87
97
  g_assert_cmpstr (dee_model_get_column_schema (fix->txn, 1), ==, "i");
 
98
 
 
99
  g_assert (dee_transaction_get_target (DEE_TRANSACTION (fix->txn)) == fix->model);
88
100
}
89
101
 
90
102
static void
1140
1152
  g_assert_cmpint (dee_model_get_n_rows (fix->model), ==, 1);
1141
1153
}
1142
1154
 
 
1155
static void
 
1156
test_basic_types (Fixture *fix, gconstpointer data)
 
1157
{
 
1158
  GError *error;
 
1159
  fix->txn = dee_transaction_new (fix->model);
 
1160
 
 
1161
  dee_model_append (fix->txn, TRUE, 27, 28, 29,
 
1162
                    G_GINT64_CONSTANT (30), G_GUINT64_CONSTANT (31),
 
1163
                    32.0, "ThirtyThree");
 
1164
 
 
1165
  DeeModelIter *iter = dee_model_get_first_iter (fix->txn);
 
1166
  g_assert (dee_model_get_bool (fix->txn, iter, 0) == TRUE);
 
1167
  g_assert (dee_model_get_uchar (fix->txn, iter, 1) == 27);
 
1168
  g_assert (dee_model_get_int32 (fix->txn, iter, 2) == 28);
 
1169
  g_assert (dee_model_get_uint32 (fix->txn, iter, 3) == 29);
 
1170
  g_assert (dee_model_get_int64 (fix->txn, iter, 4) == 30);
 
1171
  g_assert (dee_model_get_uint64 (fix->txn, iter, 5) == 31);
 
1172
  g_assert (ABS (dee_model_get_double (fix->txn, iter, 6) - 32.0) <= 0.001);
 
1173
  g_assert_cmpstr ("ThirtyThree", ==, dee_model_get_string (fix->txn, iter, 7));
 
1174
  g_assert_cmpstr ("s", ==, g_variant_get_type_string (dee_model_get_value (fix->txn, iter, 7)));
 
1175
 
 
1176
  /* COMMIT */
 
1177
  error = NULL;
 
1178
  if (!dee_transaction_commit (DEE_TRANSACTION (fix->txn), &error))
 
1179
    {
 
1180
      g_critical ("Transaction failed to commit: %s", error->message);
 
1181
      g_error_free (error);
 
1182
    }
 
1183
  if (error)
 
1184
    {
 
1185
      g_assert_not_reached ();
 
1186
    }
 
1187
}
 
1188
 
1143
1189
// FIXME tags
1144
1190
 
1145
1191
void
1238
1284
              setup, test_double_commit, teardown);
1239
1285
  g_test_add (PROXY_DOMAIN"/DoubleCommit", Fixture, 0,
1240
1286
              setup_proxy, test_double_commit, teardown);
 
1287
 
 
1288
  g_test_add (DOMAIN"/BasicTypes", Fixture, 0,
 
1289
              setup_basic_types, test_basic_types, teardown);
1241
1290
}
1242
1291