1 /*
2  *  Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
3  *
4  *  Use of this source code is governed by a BSD-style license
5  *  that can be found in the LICENSE file in the root of the source
6  *  tree. An additional intellectual property rights grant can be found
7  *  in the file PATENTS.  All contributing project authors may
8  *  be found in the AUTHORS file in the root of the source tree.
9  */
10 
11 #include "system_wrappers/source/data_log_c_helpers_unittest.h"
12 
13 #include <assert.h>
14 #include <string.h>
15 #include <stdlib.h>
16 
17 #include "system_wrappers/interface/data_log_c.h"
18 
19 enum { kTestArrayLen = 4 };
20 static const char kTableName[] = "c_wrapper_table";
21 static const char kColumnName1[] = "Scalar";
22 static const char kColumnName2[] = "Vector";
23 
WebRtcDataLogCHelper_TestCreateLog()24 int WebRtcDataLogCHelper_TestCreateLog() {
25   return WebRtcDataLog_CreateLog();
26 }
27 
WebRtcDataLogCHelper_TestReturnLog()28 int WebRtcDataLogCHelper_TestReturnLog() {
29   WebRtcDataLog_ReturnLog();
30   return 0;
31 }
32 
WebRtcDataLogCHelper_TestCombine()33 int WebRtcDataLogCHelper_TestCombine() {
34   const int kOutLen = strlen(kTableName) + 4;  /* Room for "_17" + '\0' */
35   char* combined_name = malloc(kOutLen * sizeof(char));
36   char* out_ptr = WebRtcDataLog_Combine(combined_name, kOutLen, kTableName, 17);
37   int return_code = 0;
38   if (!out_ptr) {
39     return_code = -1;
40   }
41   if (strcmp(combined_name, "c_wrapper_table_17") != 0) {
42     return_code = -2;
43   }
44   free(combined_name);
45   return return_code;
46 }
47 
WebRtcDataLogCHelper_TestAddTable()48 int WebRtcDataLogCHelper_TestAddTable() {
49   return WebRtcDataLog_AddTable(kTableName);
50 }
51 
WebRtcDataLogCHelper_TestAddColumn()52 int WebRtcDataLogCHelper_TestAddColumn() {
53   if (WebRtcDataLog_AddColumn(kTableName, kColumnName1, 1) != 0) {
54     return -1;
55   }
56   if (WebRtcDataLog_AddColumn(kTableName, kColumnName2, kTestArrayLen) != 0) {
57     return -2;
58   }
59   return 0;
60 }
61 
WebRtcDataLogCHelper_TestNextRow()62 int WebRtcDataLogCHelper_TestNextRow() {
63   return WebRtcDataLog_NextRow(kTableName);
64 }
65 
WebRtcDataLogCHelper_TestInsertCell_int()66 int WebRtcDataLogCHelper_TestInsertCell_int() {
67   return WebRtcDataLog_InsertCell_int(kTableName, kColumnName1, 17);
68 }
69 
WebRtcDataLogCHelper_TestInsertArray_int()70 int WebRtcDataLogCHelper_TestInsertArray_int() {
71   int values[kTestArrayLen] = {1, 2, 3, 4};
72   return WebRtcDataLog_InsertArray_int(kTableName, kColumnName2, values,
73                                        kTestArrayLen);
74 }
75 
WebRtcDataLogCHelper_TestInsertCell_float()76 int WebRtcDataLogCHelper_TestInsertCell_float() {
77   return WebRtcDataLog_InsertCell_float(kTableName, kColumnName1, 17.0f);
78 }
79 
WebRtcDataLogCHelper_TestInsertArray_float()80 int WebRtcDataLogCHelper_TestInsertArray_float() {
81   float values[kTestArrayLen] = {1.0f, 2.0f, 3.0f, 4.0f};
82   return WebRtcDataLog_InsertArray_float(kTableName, kColumnName2, values,
83                                          kTestArrayLen);
84 }
85 
WebRtcDataLogCHelper_TestInsertCell_double()86 int WebRtcDataLogCHelper_TestInsertCell_double() {
87   return WebRtcDataLog_InsertCell_int(kTableName, kColumnName1, 17.0);
88 }
89 
WebRtcDataLogCHelper_TestInsertArray_double()90 int WebRtcDataLogCHelper_TestInsertArray_double() {
91   double values[kTestArrayLen] = {1.0, 2.0, 3.0, 4.0};
92   return WebRtcDataLog_InsertArray_double(kTableName, kColumnName2, values,
93                                           kTestArrayLen);
94 }
95 
WebRtcDataLogCHelper_TestInsertCell_int32()96 int WebRtcDataLogCHelper_TestInsertCell_int32() {
97   return WebRtcDataLog_InsertCell_int32(kTableName, kColumnName1, 17);
98 }
99 
WebRtcDataLogCHelper_TestInsertArray_int32()100 int WebRtcDataLogCHelper_TestInsertArray_int32() {
101   int32_t values[kTestArrayLen] = {1, 2, 3, 4};
102   return WebRtcDataLog_InsertArray_int32(kTableName, kColumnName2, values,
103                                          kTestArrayLen);
104 }
105 
WebRtcDataLogCHelper_TestInsertCell_uint32()106 int WebRtcDataLogCHelper_TestInsertCell_uint32() {
107   return WebRtcDataLog_InsertCell_uint32(kTableName, kColumnName1, 17);
108 }
109 
WebRtcDataLogCHelper_TestInsertArray_uint32()110 int WebRtcDataLogCHelper_TestInsertArray_uint32() {
111   uint32_t values[kTestArrayLen] = {1, 2, 3, 4};
112   return WebRtcDataLog_InsertArray_uint32(kTableName, kColumnName2, values,
113                                           kTestArrayLen);
114 }
115 
WebRtcDataLogCHelper_TestInsertCell_int64()116 int WebRtcDataLogCHelper_TestInsertCell_int64() {
117   return WebRtcDataLog_InsertCell_int64(kTableName, kColumnName1, 17);
118 }
119 
WebRtcDataLogCHelper_TestInsertArray_int64()120 int WebRtcDataLogCHelper_TestInsertArray_int64() {
121   int64_t values[kTestArrayLen] = {1, 2, 3, 4};
122   return WebRtcDataLog_InsertArray_int64(kTableName, kColumnName2, values,
123                                          kTestArrayLen);
124 }
125