utest: rename the ut to the utests
[platform/core/uifw/libtbm.git] / utests / src / ut_tbm_bufmgr.cpp
1 /**************************************************************************
2  *
3  * Copyright 2016 Samsung Electronics co., Ltd. All Rights Reserved.
4  *
5  * Contact: Konstantin Drabeniuk <k.drabeniuk@samsung.com>
6  *
7  * Permission is hereby granted, free of charge, to any person obtaining a
8  * copy of this software and associated documentation files (the
9  * "Software"), to deal in the Software without restriction, including
10  * without limitation the rights to use, copy, modify, merge, publish,
11  * distribute, sub license, and/or sell copies of the Software, and to
12  * permit persons to whom the Software is furnished to do so, subject to
13  * the following conditions:
14  *
15  * The above copyright notice and this permission notice (including the
16  * next paragraph) shall be included in all copies or substantial portions
17  * of the Software.
18  *
19  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
22  * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
23  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
24  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
25  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26  *
27 **************************************************************************/
28
29 #include "gtest/gtest.h"
30
31 #include "ut_tbm_bufmgr.h"
32
33 #include "pthread_stubs.h"
34 #include "stdlib_stubs.h"
35
36 #define pthread_mutex_lock ut_pthread_mutex_lock
37 #define pthread_mutex_unlock ut_pthread_mutex_unlock
38 #define pthread_mutex_init ut_pthread_mutex_init
39 #define calloc ut_calloc
40 #define free ut_free
41
42 #include "tbm_bufmgr.c"
43 #include "tbm_bufmgr_stubs.h"
44
45 static void _init_test()
46 {
47         gBufMgr = NULL;
48         PTHREAD_MUTEX_INIT_ERROR = 0;
49         CALLOC_ERROR = 0;
50         FREE_CALLED = 0;
51         FREE_PTR = NULL;
52         FREE_TESTED_PTR = NULL;
53         free_called_for_tested_ptr = 0;
54         free_call_count = 0;
55         GETENV_ERROR = 0;
56         UT_TBM_ERROR = 0;
57         TBM_BO_ALLOC_ERROR = 0;
58         TBM_BO_IMPORT_ERROR = 0;
59         bo_ret_flags = TBM_BO_SCANOUT;
60 }
61
62 /* tbm_bufmgr_bind_native_display() */
63
64 TEST(tbm_bufmgr_bind_native_display, work_flow_success_3)
65 {
66         int expected = 1;
67         struct _tbm_bufmgr bufmgr;
68         struct _tbm_bufmgr_backend backend;
69         int actual;
70
71         _init_test();
72
73         gBufMgr = &bufmgr;
74         memset(gBufMgr, 0, sizeof(bufmgr));
75
76         bufmgr.backend = &backend;
77         backend.bufmgr_bind_native_display = ut_bufmgr_bind_native_display;
78
79         actual = tbm_bufmgr_bind_native_display(&bufmgr, NULL);
80
81         ASSERT_EQ(expected, actual);
82 }
83
84 TEST(tbm_bufmgr_bind_native_display, work_flow_success_2)
85 {
86         int expected = 0;
87         struct _tbm_bufmgr bufmgr;
88         struct _tbm_bufmgr_backend backend;
89         int actual;
90
91         _init_test();
92
93         gBufMgr = &bufmgr;
94         memset(gBufMgr, 0, sizeof(bufmgr));
95
96         bufmgr.backend = &backend;
97         backend.bufmgr_bind_native_display = ut_bufmgr_bind_native_display;
98         UT_TBM_ERROR = 1;
99
100         actual = tbm_bufmgr_bind_native_display(&bufmgr, NULL);
101
102         ASSERT_EQ(expected, actual);
103 }
104
105 TEST(tbm_bufmgr_bind_native_display, work_flow_success_1)
106 {
107         int expected = 1;
108         struct _tbm_bufmgr bufmgr;
109         struct _tbm_bufmgr_backend backend;
110         int actual;
111
112         _init_test();
113
114         gBufMgr = &bufmgr;
115         memset(gBufMgr, 0, sizeof(bufmgr));
116
117         bufmgr.backend = &backend;
118         backend.bufmgr_bind_native_display = NULL;
119
120         actual = tbm_bufmgr_bind_native_display(&bufmgr, NULL);
121
122         ASSERT_EQ(expected, actual);
123 }
124
125 TEST(tbm_bufmgr_bind_native_display, null_ptr_fail_1)
126 {
127         int expected = 0;
128         int actual;
129
130         _init_test();
131
132         actual = tbm_bufmgr_bind_native_display(NULL, NULL);
133
134         ASSERT_EQ(expected, actual);
135 }
136
137 /* tbm_bo_get_flags() */
138
139 TEST(tbm_bo_get_flags, work_flow_success_2)
140 {
141         int expected_flags = 5;
142         struct _tbm_bo bo;
143         struct _tbm_bufmgr bufmgr;
144         int actual_flags;
145
146         _init_test();
147
148         LIST_INITHEAD(&bufmgr.bo_list);
149         LIST_ADD(&bo.item_link, &bufmgr.bo_list);
150         gBufMgr = &bufmgr;
151         bo.flags = expected_flags;
152
153         actual_flags = tbm_bo_get_flags(&bo);
154
155         ASSERT_EQ(actual_flags, expected_flags);
156 }
157
158 TEST(tbm_bo_get_flags, work_flow_success_1)
159 {
160         int expected = 0;
161         struct _tbm_bo bo;
162         struct _tbm_bufmgr bufmgr;
163         int actual;
164
165         _init_test();
166
167         LIST_INITHEAD(&bufmgr.bo_list);
168         gBufMgr = &bufmgr;
169
170         actual = tbm_bo_get_flags(&bo);
171
172         ASSERT_EQ(actual, expected);
173 }
174
175 TEST(tbm_bo_get_flags, null_ptr_fail_1)
176 {
177         int expected = 0;
178         int actual;
179
180         _init_test();
181
182         actual = tbm_bo_get_flags(NULL);
183
184         ASSERT_EQ(actual, expected);
185 }
186
187
188 /* tbm_bufmgr_get_capability() */
189
190 TEST(tbm_bufmgr_get_capability, work_flow_success_2)
191 {
192         unsigned int capability = TBM_BUFMGR_CAPABILITY_NONE;
193         unsigned int expected_capability = TBM_BUFMGR_CAPABILITY_SHARE_FD;
194         struct _tbm_bufmgr bufmgr;
195         struct _tbm_bufmgr_backend backend;
196
197         _init_test();
198
199         gBufMgr = &bufmgr;
200         memset(gBufMgr, 0, sizeof(bufmgr));
201
202         bufmgr.backend = &backend;
203         backend.bo_import = NULL;
204         backend.bo_export = NULL;
205         backend.bo_import_fd = ut_bo_import_fd;
206         backend.bo_export_fd = ut_bo_export_fd;
207         bufmgr.capabilities = TBM_BUFMGR_CAPABILITY_SHARE_FD;
208
209         capability = tbm_bufmgr_get_capability(&bufmgr);
210
211         ASSERT_EQ(capability, expected_capability);
212 }
213
214 TEST(tbm_bufmgr_get_capability, work_flow_success_1)
215 {
216         unsigned int capability = TBM_BUFMGR_CAPABILITY_SHARE_KEY;
217         unsigned int expected_capability = TBM_BUFMGR_CAPABILITY_NONE;
218
219         _init_test();
220
221         capability = tbm_bufmgr_get_capability(NULL);
222
223         ASSERT_EQ(capability, expected_capability);
224 }
225
226 /* tbm_get_last_error() */
227
228 TEST(tbm_get_last_error, work_flow_success_1)
229 {
230         tbm_last_error = TBM_BO_ERROR_GET_FD_FAILED;
231         tbm_error_e expected_error = tbm_last_error;
232
233         _init_test();
234
235         tbm_error_e error = tbm_get_last_error();
236
237         ASSERT_EQ(error, expected_error);
238 }
239
240 /* tbm_bo_delete_user_data() */
241
242 TEST(tbm_bo_delete_user_data, work_flow_success_4)
243 {
244         unsigned int key = 5;
245         int expected = 1;
246         struct _tbm_bo bo;
247         struct _tbm_bufmgr bufmgr;
248         int expected_data;
249         int actual;
250
251         _init_test();
252
253         LIST_INITHEAD(&bufmgr.bo_list);
254         LIST_ADD(&bo.item_link, &bufmgr.bo_list);
255         gBufMgr = &bufmgr;
256         LIST_INITHEAD(&bo.user_data_list);
257         tbm_user_data *user_data = (tbm_user_data *)calloc(1, sizeof(tbm_user_data));
258         user_data->data = &expected_data;
259         user_data->key = key;
260         user_data->free_func = NULL;
261         LIST_INITHEAD(&bo.user_data_list);
262         LIST_ADD(&user_data->item_link, &bo.user_data_list);
263         FREE_TESTED_PTR = user_data;
264
265         actual = tbm_bo_delete_user_data(&bo, key);
266
267         ASSERT_EQ(actual, expected);
268         ASSERT_EQ(free_called_for_tested_ptr, 1);
269 }
270
271 TEST(tbm_bo_delete_user_data, work_flow_success_3)
272 {
273         unsigned int key = 5;
274         int expected = 0;
275         struct _tbm_bo bo;
276         struct _tbm_bufmgr bufmgr;
277         int expected_data;
278         int actual;
279
280         _init_test();
281
282         LIST_INITHEAD(&bufmgr.bo_list);
283         LIST_ADD(&bo.item_link, &bufmgr.bo_list);
284         gBufMgr = &bufmgr;
285         LIST_INITHEAD(&bo.user_data_list);
286         tbm_user_data user_data;
287         user_data.data = &expected_data;
288         user_data.key = key - 1;
289         LIST_INITHEAD(&bo.user_data_list);
290         LIST_ADD(&user_data.item_link, &bo.user_data_list);
291
292         actual = tbm_bo_delete_user_data(&bo, key);
293
294         ASSERT_EQ(actual, expected);
295 }
296
297 TEST(tbm_bo_delete_user_data, work_flow_success_2)
298 {
299         int expected = 0;
300         struct _tbm_bo bo;
301         struct _tbm_bufmgr bufmgr;
302         int actual;
303
304         _init_test();
305
306         LIST_INITHEAD(&bufmgr.bo_list);
307         LIST_ADD(&bo.item_link, &bufmgr.bo_list);
308         gBufMgr = &bufmgr;
309         LIST_INITHEAD(&bo.user_data_list);
310
311         actual = tbm_bo_delete_user_data(&bo, 1);
312
313         ASSERT_EQ(actual, expected);
314 }
315
316 TEST(tbm_bo_delete_user_data, work_flow_success_1)
317 {
318         int expected = 0;
319         struct _tbm_bo bo;
320         struct _tbm_bufmgr bufmgr;
321         int actual;
322
323         _init_test();
324
325         LIST_INITHEAD(&bufmgr.bo_list);
326         gBufMgr = &bufmgr;
327
328         actual = tbm_bo_delete_user_data(&bo, 1);
329
330         ASSERT_EQ(actual, expected);
331 }
332
333 TEST(tbm_bo_delete_user_data, null_ptr_fail_1)
334 {
335         int expected = 0;
336         int actual;
337
338         _init_test();
339
340         actual = tbm_bo_delete_user_data(NULL, 1);
341
342         ASSERT_EQ(actual, expected);
343 }
344
345 /* tbm_bo_get_user_data() */
346
347 TEST(tbm_bo_get_user_data, work_flow_success_5)
348 {
349         unsigned int key = 5;
350         void *data;
351         int expected = 1;
352         struct _tbm_bo bo;
353         struct _tbm_bufmgr bufmgr;
354         int expected_data;
355         int actual;
356
357         _init_test();
358
359         LIST_INITHEAD(&bufmgr.bo_list);
360         LIST_ADD(&bo.item_link, &bufmgr.bo_list);
361         gBufMgr = &bufmgr;
362         LIST_INITHEAD(&bo.user_data_list);
363         tbm_user_data user_data;
364         user_data.data = &expected_data;
365         user_data.key = key;
366         LIST_INITHEAD(&bo.user_data_list);
367         LIST_ADD(&user_data.item_link, &bo.user_data_list);
368
369         actual = tbm_bo_get_user_data(&bo, key, &data);
370
371         ASSERT_EQ(actual, expected);
372         ASSERT_TRUE(data == &expected_data);
373 }
374
375 TEST(tbm_bo_get_user_data, work_flow_success_4)
376 {
377         unsigned int key = 5;
378         void *data;
379         int expected = 0;
380         struct _tbm_bo bo;
381         struct _tbm_bufmgr bufmgr;
382         int expected_data;
383         tbm_user_data user_data;
384         int actual;
385
386         _init_test();
387
388         LIST_INITHEAD(&bufmgr.bo_list);
389         LIST_ADD(&bo.item_link, &bufmgr.bo_list);
390         gBufMgr = &bufmgr;
391         LIST_INITHEAD(&bo.user_data_list);
392         user_data.data = &expected_data;
393         user_data.key = key - 1;
394         LIST_INITHEAD(&bo.user_data_list);
395         LIST_ADD(&user_data.item_link, &bo.user_data_list);
396
397         actual = tbm_bo_get_user_data(&bo, key, &data);
398
399         ASSERT_EQ(actual, expected);
400 }
401
402 TEST(tbm_bo_get_user_data, work_flow_success_3)
403 {
404         void *data;
405         int expected = 0;
406         struct _tbm_bo bo;
407         struct _tbm_bufmgr bufmgr;
408         int actual;
409
410         _init_test();
411
412         LIST_INITHEAD(&bufmgr.bo_list);
413         LIST_ADD(&bo.item_link, &bufmgr.bo_list);
414         gBufMgr = &bufmgr;
415         LIST_INITHEAD(&bo.user_data_list);
416
417         actual = tbm_bo_get_user_data(&bo, 1, &data);
418
419         ASSERT_EQ(actual, expected);
420 }
421
422 TEST(tbm_bo_get_user_data, work_flow_success_2)
423 {
424         int expected = 0;
425         struct _tbm_bo bo;
426         struct _tbm_bufmgr bufmgr;
427         int actual;
428
429         _init_test();
430
431         LIST_INITHEAD(&bufmgr.bo_list);
432         LIST_ADD(&bo.item_link, &bufmgr.bo_list);
433         gBufMgr = &bufmgr;
434
435         actual = tbm_bo_get_user_data(&bo, 1, NULL);
436
437         ASSERT_EQ(actual, expected);
438 }
439
440 TEST(tbm_bo_get_user_data, work_flow_success_1)
441 {
442         int expected = 0;
443         struct _tbm_bo bo;
444         struct _tbm_bufmgr bufmgr;
445         int actual;
446
447         _init_test();
448
449         LIST_INITHEAD(&bufmgr.bo_list);
450         gBufMgr = &bufmgr;
451
452         actual = tbm_bo_get_user_data(&bo, 1, NULL);
453
454         ASSERT_EQ(actual, expected);
455 }
456
457 TEST(tbm_bo_get_user_data, null_ptr_fail_1)
458 {
459         int expected = 0;
460         int actual;
461
462         _init_test();
463
464         actual = tbm_bo_get_user_data(NULL, 1, NULL);
465
466         ASSERT_EQ(actual, expected);
467 }
468
469 /* tbm_bo_set_user_data() */
470
471 TEST(tbm_bo_set_user_data, work_flow_success_3)
472 {
473         unsigned int key = 5;
474         int expected = 1;
475         struct _tbm_bo bo;
476         struct _tbm_bufmgr bufmgr;
477         int data, actual;
478
479         _init_test();
480
481         LIST_INITHEAD(&bufmgr.bo_list);
482         LIST_ADD(&bo.item_link, &bufmgr.bo_list);
483         gBufMgr = &bufmgr;
484         tbm_user_data user_data;
485         user_data.data = NULL;
486         user_data.free_func = NULL;
487         user_data.key = key;
488         LIST_INITHEAD(&bo.user_data_list);
489         LIST_ADD(&user_data.item_link, &bo.user_data_list);
490
491         actual = tbm_bo_set_user_data(&bo, key, &data);
492
493         ASSERT_EQ(actual, expected);
494         ASSERT_TRUE(user_data.data == &data);
495 }
496
497 TEST(tbm_bo_set_user_data, work_flow_success_2)
498 {
499         unsigned int key = 5;
500         int expected = 0;
501         struct _tbm_bo bo;
502         struct _tbm_bufmgr bufmgr;
503         int actual;
504
505         _init_test();
506
507         LIST_INITHEAD(&bufmgr.bo_list);
508         LIST_ADD(&bo.item_link, &bufmgr.bo_list);
509         gBufMgr = &bufmgr;
510         tbm_user_data user_data;
511         user_data.key = key - 1;
512         LIST_INITHEAD(&bo.user_data_list);
513         LIST_ADD(&user_data.item_link, &bo.user_data_list);
514
515         actual = tbm_bo_set_user_data(&bo, key, NULL);
516
517         ASSERT_EQ(actual, expected);
518 }
519
520 TEST(tbm_bo_set_user_data, work_flow_success_1)
521 {
522         int expected = 0;
523         struct _tbm_bo bo;
524         struct _tbm_bufmgr bufmgr;
525         int actual;
526
527         _init_test();
528
529         LIST_INITHEAD(&bufmgr.bo_list);
530         gBufMgr = &bufmgr;
531
532         actual = tbm_bo_set_user_data(&bo, 1, NULL);
533
534         ASSERT_EQ(actual, expected);
535 }
536
537 TEST(tbm_bo_set_user_data, null_ptr_fail_1)
538 {
539         int expected = 0;
540         int actual;
541
542         _init_test();
543
544         actual = tbm_bo_set_user_data(NULL, 1, NULL);
545
546         ASSERT_EQ(actual, expected);
547 }
548
549 /* tbm_bo_add_user_data() */
550
551 TEST(tbm_bo_add_user_data, work_flow_success_4)
552 {
553         tbm_user_data *data = NULL;
554         unsigned long key = 5;
555         int expected = 1;
556         struct _tbm_bo bo;
557         struct _tbm_bufmgr bufmgr;
558         int actual;
559
560         _init_test();
561
562         LIST_INITHEAD(&bufmgr.bo_list);
563         LIST_ADD(&bo.item_link, &bufmgr.bo_list);
564         gBufMgr = &bufmgr;
565         tbm_user_data user_data;
566         user_data.key = key - 1;
567         LIST_INITHEAD(&bo.user_data_list);
568         LIST_ADD(&user_data.item_link, &bo.user_data_list);
569
570         actual = tbm_bo_add_user_data(&bo, key, ut_tbm_data_free);
571
572         ASSERT_EQ(actual, expected);
573         data = user_data_lookup(&bo.user_data_list, key);
574         ASSERT_TRUE(data != NULL);
575         tbm_user_data copy_data = *data;
576         free(data);
577         ASSERT_EQ(copy_data.key, key);
578         ASSERT_TRUE(copy_data.free_func == ut_tbm_data_free);
579         ASSERT_TRUE(copy_data.data == NULL);
580 }
581
582 TEST(tbm_bo_add_user_data, work_flow_success_3)
583 {
584         unsigned long key = 5;
585         int expected = 0;
586         struct _tbm_bo bo;
587         struct _tbm_bufmgr bufmgr;
588         int actual;
589
590         _init_test();
591
592         LIST_INITHEAD(&bufmgr.bo_list);
593         LIST_ADD(&bo.item_link, &bufmgr.bo_list);
594         gBufMgr = &bufmgr;
595         tbm_user_data user_data;
596         user_data.key = key - 1;
597         LIST_INITHEAD(&bo.user_data_list);
598         LIST_ADD(&user_data.item_link, &bo.user_data_list);
599         CALLOC_ERROR = 1;
600
601         actual = tbm_bo_add_user_data(&bo, key, NULL);
602
603         ASSERT_EQ(actual, expected);
604 }
605
606 TEST(tbm_bo_add_user_data, work_flow_success_2)
607 {
608         unsigned long key = 5;
609         int expected = 0;
610         struct _tbm_bo bo;
611         struct _tbm_bufmgr bufmgr;
612         int actual;
613
614         _init_test();
615
616         LIST_INITHEAD(&bufmgr.bo_list);
617         LIST_ADD(&bo.item_link, &bufmgr.bo_list);
618         gBufMgr = &bufmgr;
619         tbm_user_data user_data;
620         user_data.key = key;
621         LIST_INITHEAD(&bo.user_data_list);
622         LIST_ADD(&user_data.item_link, &bo.user_data_list);
623
624         actual = tbm_bo_add_user_data(&bo, key, NULL);
625
626         ASSERT_EQ(actual, expected);
627 }
628
629 TEST(tbm_bo_add_user_data, work_flow_success_1)
630 {
631         int expected = 0;
632         struct _tbm_bo bo;
633         struct _tbm_bufmgr bufmgr;
634         int actual;
635
636         _init_test();
637
638         LIST_INITHEAD(&bufmgr.bo_list);
639         gBufMgr = &bufmgr;
640
641         actual = tbm_bo_add_user_data(&bo, 1, NULL);
642
643         ASSERT_EQ(actual, expected);
644 }
645
646 TEST(tbm_bo_add_user_data, null_ptr_fail_1)
647 {
648         int expected = 0;
649         int actual;
650
651         _init_test();
652
653         actual = tbm_bo_add_user_data(NULL, 1, NULL);
654
655         ASSERT_EQ(actual, expected);
656 }
657
658 /* tbm_bo_locked() */
659
660 TEST(tbm_bo_locked, work_flow_success_4)
661 {
662         int expected = 0;
663         struct _tbm_bo bo;
664         struct _tbm_bufmgr bufmgr;
665         int actual;
666
667         _init_test();
668
669         LIST_INITHEAD(&bufmgr.bo_list);
670         LIST_ADD(&bo.item_link, &bufmgr.bo_list);
671         gBufMgr = &bufmgr;
672         bo.bufmgr = &bufmgr;
673         bufmgr.lock_type = LOCK_TRY_ONCE;
674         bo.lock_cnt = 0;
675
676         actual = tbm_bo_locked(&bo);
677
678         ASSERT_EQ(actual, expected);
679 }
680
681 TEST(tbm_bo_locked, work_flow_success_3)
682 {
683         int expected = 1;
684         struct _tbm_bo bo;
685         struct _tbm_bufmgr bufmgr;
686         int actual;
687
688         _init_test();
689
690         LIST_INITHEAD(&bufmgr.bo_list);
691         LIST_ADD(&bo.item_link, &bufmgr.bo_list);
692         gBufMgr = &bufmgr;
693         bo.bufmgr = &bufmgr;
694         bufmgr.lock_type = LOCK_TRY_ONCE;
695         bo.lock_cnt = 10;
696
697         actual = tbm_bo_locked(&bo);
698
699         ASSERT_EQ(actual, expected);
700 }
701
702 TEST(tbm_bo_locked, work_flow_success_2)
703 {
704         int expected = 0;
705         struct _tbm_bo bo;
706         struct _tbm_bufmgr bufmgr;
707         int actual;
708
709         _init_test();
710
711         LIST_INITHEAD(&bufmgr.bo_list);
712         LIST_ADD(&bo.item_link, &bufmgr.bo_list);
713         gBufMgr = &bufmgr;
714         bo.bufmgr = &bufmgr;
715         bufmgr.lock_type = LOCK_TRY_NEVER;
716
717         actual = tbm_bo_locked(&bo);
718
719         ASSERT_EQ(actual, expected);
720 }
721
722 TEST(tbm_bo_locked, work_flow_success_1)
723 {
724         int expected = 0;
725         struct _tbm_bo bo;
726         struct _tbm_bufmgr bufmgr;
727         int actual;
728
729         _init_test();
730
731         LIST_INITHEAD(&bufmgr.bo_list);
732         gBufMgr = &bufmgr;
733
734         actual = tbm_bo_locked(&bo);
735
736         ASSERT_EQ(actual, expected);
737 }
738
739 TEST(tbm_bo_locked, null_ptr_fail_1)
740 {
741         int expected = 0;
742         int actual;
743
744         _init_test();
745
746         actual = tbm_bo_locked(NULL);
747
748         ASSERT_EQ(actual, expected);
749 }
750
751 /* tbm_bo_swap() */
752
753 TEST(tbm_bo_swap, work_flow_success_3)
754 {
755         int priv1 = 10;
756         int priv2 = 20;
757         int expected = 1;
758         struct _tbm_bo bo1;
759         struct _tbm_bo bo2;
760         struct _tbm_bufmgr bufmgr;
761         struct _tbm_bufmgr bufmgr2;
762         struct _tbm_bufmgr_backend backend1;
763         struct _tbm_bufmgr_backend backend2;
764         int actual;
765
766         _init_test();
767
768         LIST_INITHEAD(&bufmgr.bo_list);
769         LIST_ADD(&bo1.item_link, &bufmgr.bo_list);
770         LIST_ADD(&bo2.item_link, &bufmgr.bo_list);
771         gBufMgr = &bufmgr;
772         bufmgr.backend = &backend1;
773         bufmgr2.backend = &backend2;
774         bo1.bufmgr = &bufmgr;
775         bo2.bufmgr = &bufmgr2;
776         backend1.bo_size = ut_bo_size;
777         backend2.bo_size = ut_bo2_size;
778         bo1.priv = &priv1;
779         bo2.priv = &priv2;
780
781         actual = tbm_bo_swap(&bo1, &bo2);
782
783         ASSERT_EQ(actual, expected);
784         ASSERT_TRUE(bo1.priv == &priv2);
785         ASSERT_TRUE(bo2.priv == &priv1);
786 }
787
788 TEST(tbm_bo_swap, work_flow_success_2)
789 {
790         int expected = 0;
791         struct _tbm_bo bo1;
792         struct _tbm_bo bo2;
793         struct _tbm_bufmgr bufmgr;
794         int actual;
795
796         _init_test();
797
798         LIST_INITHEAD(&bufmgr.bo_list);
799         LIST_ADD(&bo1.item_link, &bufmgr.bo_list);
800         gBufMgr = &bufmgr;
801
802         actual = tbm_bo_swap(&bo1, &bo2);
803
804         ASSERT_EQ(actual, expected);
805 }
806
807 TEST(tbm_bo_swap, work_flow_success_1)
808 {
809         int expected = 0;
810         struct _tbm_bo bo1;
811         struct _tbm_bo bo2;
812         struct _tbm_bufmgr bufmgr;
813         int actual;
814
815         _init_test();
816
817         LIST_INITHEAD(&bufmgr.bo_list);
818         LIST_ADD(&bo2.item_link, &bufmgr.bo_list);
819         gBufMgr = &bufmgr;
820
821         actual = tbm_bo_swap(&bo1, &bo2);
822
823         ASSERT_EQ(actual, expected);
824 }
825
826 TEST(tbm_bo_swap, null_ptr_fail_2)
827 {
828         int expected = 0;
829         struct _tbm_bo bo1;
830         struct _tbm_bufmgr bufmgr;
831         int actual;
832
833         _init_test();
834
835         LIST_INITHEAD(&bufmgr.bo_list);
836         gBufMgr = &bufmgr;
837
838         actual = tbm_bo_swap(&bo1, NULL);
839
840         ASSERT_EQ(actual, expected);
841 }
842
843 TEST(tbm_bo_swap, null_ptr_fail_1)
844 {
845         int expected = 0;
846         struct _tbm_bo bo2;
847         struct _tbm_bufmgr bufmgr;
848         int actual;
849
850         _init_test();
851
852         LIST_INITHEAD(&bufmgr.bo_list);
853         gBufMgr = &bufmgr;
854
855         actual = tbm_bo_swap(NULL, &bo2);
856
857         ASSERT_EQ(actual, expected);
858 }
859
860 /* tbm_bo_unmap() */
861
862 TEST(tbm_bo_unmap_null, work_flow_success_3)
863 {
864         int not_expected = 0;
865         struct _tbm_bo bo;
866         struct _tbm_bufmgr bufmgr;
867         struct _tbm_bufmgr_backend backend;
868         int actual;
869
870         _init_test();
871
872         LIST_INITHEAD(&bufmgr.bo_list);
873         LIST_ADD(&bo.item_link, &bufmgr.bo_list);
874         gBufMgr = &bufmgr;
875         bo.bufmgr = &bufmgr;
876         bufmgr.backend = &backend;
877         backend.bo_unmap = ut_bo_unmap;
878         bufmgr.lock_type = LOCK_TRY_NEVER;
879
880         actual = tbm_bo_unmap(&bo);
881
882         ASSERT_NE(actual, not_expected);
883 }
884
885 TEST(tbm_bo_unmap_null, work_flow_success_2)
886 {
887         tbm_error_e expected_last_error = TBM_BO_ERROR_UNMAP_FAILED;
888         int expected = 0;
889         struct _tbm_bo bo;
890         struct _tbm_bufmgr bufmgr;
891         struct _tbm_bufmgr_backend backend;
892         int actual;
893
894         _init_test();
895
896         LIST_INITHEAD(&bufmgr.bo_list);
897         LIST_ADD(&bo.item_link, &bufmgr.bo_list);
898         gBufMgr = &bufmgr;
899         bo.bufmgr = &bufmgr;
900         bufmgr.backend = &backend;
901         backend.bo_unmap = ut_bo_unmap;
902         UT_TBM_ERROR = 1;
903
904         actual = tbm_bo_unmap(&bo);
905
906         ASSERT_EQ(actual, expected);
907         ASSERT_EQ(tbm_last_error, expected_last_error);
908 }
909
910 TEST(tbm_bo_unmap_null, work_flow_success_1)
911 {
912         int expected = 0;
913         struct _tbm_bo bo;
914         struct _tbm_bufmgr bufmgr;
915         int actual;
916
917         _init_test();
918
919         LIST_INITHEAD(&bufmgr.bo_list);
920         gBufMgr = &bufmgr;
921
922         actual = tbm_bo_unmap(&bo);
923
924         ASSERT_EQ(actual, expected);
925 }
926
927 TEST(tbm_bo_unmap, null_ptr_fail_1)
928 {
929         int expected = 0;
930         int actual;
931
932         _init_test();
933
934         actual = tbm_bo_unmap(NULL);
935
936         ASSERT_EQ(actual, expected);
937 }
938
939 /* tbm_bo_map() */
940
941 TEST(tbm_bo_map, work_flow_success_4)
942 {
943         struct _tbm_bo bo;
944         bo.map_cnt = 5;
945         unsigned int expected_map_cnt = bo.map_cnt + 1;
946         struct _tbm_bufmgr bufmgr;
947         struct _tbm_bufmgr_backend backend;
948         tbm_bo_handle handle;
949
950         _init_test();
951
952         LIST_INITHEAD(&bufmgr.bo_list);
953         LIST_ADD(&bo.item_link, &bufmgr.bo_list);
954         gBufMgr = &bufmgr;
955         bufmgr.lock_type = LOCK_TRY_NEVER;
956         bo.bufmgr = &bufmgr;
957         bufmgr.backend = &backend;
958         backend.bo_map = ut_bo_map;
959
960         handle = tbm_bo_map(&bo, 1, 1);
961
962         ASSERT_TRUE(handle.ptr != NULL);
963         ASSERT_EQ(bo.map_cnt, expected_map_cnt);
964 }
965
966 TEST(tbm_bo_map, work_flow_success_3)
967 {
968         tbm_error_e expected_last_error = TBM_BO_ERROR_MAP_FAILED;
969         tbm_bo_handle expected_handle;
970         struct _tbm_bo bo;
971         struct _tbm_bufmgr bufmgr;
972         struct _tbm_bufmgr_backend backend;
973         tbm_bo_handle handle;
974
975         _init_test();
976
977         expected_handle.ptr = NULL;
978         LIST_INITHEAD(&bufmgr.bo_list);
979         LIST_ADD(&bo.item_link, &bufmgr.bo_list);
980         gBufMgr = &bufmgr;
981         bufmgr.lock_type = LOCK_TRY_NEVER;
982         bo.bufmgr = &bufmgr;
983         bufmgr.backend = &backend;
984         backend.bo_map = ut_bo_map;
985         UT_TBM_ERROR = 1;
986
987         handle = tbm_bo_map(&bo, 1, 1);
988
989         ASSERT_TRUE(handle.ptr == expected_handle.ptr);
990         ASSERT_EQ(tbm_last_error, expected_last_error);
991 }
992
993 TEST(tbm_bo_map, work_flow_success_2)
994 {
995         tbm_error_e expected_last_error = TBM_BO_ERROR_LOCK_FAILED;
996         tbm_bo_handle expected_handle;
997         struct _tbm_bo bo;
998         struct _tbm_bufmgr bufmgr;
999         tbm_bo_handle handle;
1000
1001         _init_test();
1002
1003         expected_handle.ptr = NULL;
1004         LIST_INITHEAD(&bufmgr.bo_list);
1005         LIST_ADD(&bo.item_link, &bufmgr.bo_list);
1006         gBufMgr = &bufmgr;
1007         bufmgr.lock_type = LOCK_TRY_NEVER + 546;
1008         bo.bufmgr = &bufmgr;
1009
1010         handle = tbm_bo_map(&bo, 1, 1);
1011
1012         ASSERT_TRUE(handle.ptr == expected_handle.ptr);
1013         ASSERT_EQ(tbm_last_error, expected_last_error);
1014 }
1015
1016 TEST(tbm_bo_map, work_flow_success_1)
1017 {
1018         tbm_bo_handle expected_handle;
1019         expected_handle.ptr = NULL;
1020         struct _tbm_bo bo;
1021         struct _tbm_bufmgr bufmgr;
1022
1023         _init_test();
1024
1025         LIST_INITHEAD(&bufmgr.bo_list);
1026         gBufMgr = &bufmgr;
1027
1028         tbm_bo_handle handle = tbm_bo_map(&bo, 1, 1);
1029
1030         ASSERT_TRUE(handle.ptr == expected_handle.ptr);
1031 }
1032
1033 TEST(tbm_bo_map, null_ptr_fail_1)
1034 {
1035         tbm_bo_handle expected_handle;
1036         expected_handle.ptr = NULL;
1037         tbm_bo_handle handle;
1038
1039         _init_test();
1040
1041         handle = tbm_bo_map(NULL, 1, 1);
1042
1043         ASSERT_TRUE(handle.ptr == expected_handle.ptr);
1044 }
1045
1046 /* tbm_bo_get_handle() */
1047
1048 TEST(tbm_bo_get_handle, work_flow_success_3)
1049 {
1050         struct _tbm_bo bo;
1051         struct _tbm_bufmgr bufmgr;
1052         struct _tbm_bufmgr_backend backend;
1053         tbm_bo_handle handle;
1054
1055         _init_test();
1056
1057         LIST_INITHEAD(&bufmgr.bo_list);
1058         LIST_ADD(&bo.item_link, &bufmgr.bo_list);
1059         gBufMgr = &bufmgr;
1060         bo.bufmgr = &bufmgr;
1061         bufmgr.backend = &backend;
1062         backend.bo_get_handle = ut_bo_get_handle;
1063
1064         handle = tbm_bo_get_handle(&bo, 1);
1065
1066         ASSERT_TRUE(handle.ptr != NULL);
1067 }
1068
1069 TEST(tbm_bo_get_handle, work_flow_success_2)
1070 {
1071         tbm_bo_handle expected_handle;
1072         expected_handle.ptr = NULL;
1073         tbm_error_e expected_last_result = TBM_BO_ERROR_GET_HANDLE_FAILED;
1074         struct _tbm_bo bo;
1075         struct _tbm_bufmgr bufmgr;
1076         struct _tbm_bufmgr_backend backend;
1077
1078         _init_test();
1079
1080         LIST_INITHEAD(&bufmgr.bo_list);
1081         LIST_ADD(&bo.item_link, &bufmgr.bo_list);
1082         gBufMgr = &bufmgr;
1083         bo.bufmgr = &bufmgr;
1084         bufmgr.backend = &backend;
1085         backend.bo_get_handle = ut_bo_get_handle;
1086         UT_TBM_ERROR = 1;
1087
1088         tbm_bo_handle handle = tbm_bo_get_handle(&bo, 1);
1089
1090         ASSERT_TRUE(handle.ptr == expected_handle.ptr);
1091         ASSERT_EQ(tbm_last_error, expected_last_result);
1092 }
1093
1094 TEST(tbm_bo_get_handle, work_flow_success_1)
1095 {
1096         tbm_bo_handle expected_handle;
1097         expected_handle.ptr = NULL;
1098         struct _tbm_bo bo;
1099         struct _tbm_bufmgr bufmgr;
1100         tbm_bo_handle handle;
1101
1102         _init_test();
1103
1104         LIST_INITHEAD(&bufmgr.bo_list);
1105         gBufMgr = &bufmgr;
1106
1107         handle = tbm_bo_get_handle(&bo, 1);
1108
1109         ASSERT_TRUE(handle.ptr == expected_handle.ptr);
1110 }
1111
1112 TEST(tbm_bo_get_handle, null_ptr_fail_1)
1113 {
1114         tbm_bo_handle expected_handle;
1115         expected_handle.ptr = NULL;
1116         tbm_bo_handle handle;
1117
1118         _init_test();
1119
1120         handle = tbm_bo_get_handle(NULL, 1);
1121
1122         ASSERT_TRUE(handle.ptr == expected_handle.ptr);
1123 }
1124
1125 /* tbm_bo_export_fd() */
1126
1127 TEST(tbm_bo_export_fd, work_flow_success_3)
1128 {
1129         struct _tbm_bo bo;
1130         struct _tbm_bufmgr bufmgr;
1131         struct _tbm_bufmgr_backend backend;
1132         int key;
1133
1134         _init_test();
1135
1136         LIST_INITHEAD(&bufmgr.bo_list);
1137         LIST_ADD(&bo.item_link, &bufmgr.bo_list);
1138         gBufMgr = &bufmgr;
1139         bo.bufmgr = &bufmgr;
1140         bufmgr.backend = &backend;
1141         backend.bo_export_fd = ut_bo_export_fd;
1142
1143         key = tbm_bo_export_fd(&bo);
1144
1145         ASSERT_GE(key, 0);
1146 }
1147
1148 TEST(tbm_bo_export_fd, work_flow_success_2)
1149 {
1150         tbm_error_e expected_last_result = TBM_BO_ERROR_EXPORT_FD_FAILED;
1151         int expected_key = -1;
1152         struct _tbm_bo bo;
1153         struct _tbm_bufmgr bufmgr;
1154         struct _tbm_bufmgr_backend backend;
1155         int key;
1156
1157         _init_test();
1158
1159         LIST_INITHEAD(&bufmgr.bo_list);
1160         LIST_ADD(&bo.item_link, &bufmgr.bo_list);
1161         gBufMgr = &bufmgr;
1162         bo.bufmgr = &bufmgr;
1163         bufmgr.backend = &backend;
1164         backend.bo_export_fd = ut_bo_export_fd;
1165         UT_TBM_ERROR = 1;
1166
1167         key = tbm_bo_export_fd(&bo);
1168
1169         ASSERT_EQ(key, expected_key);
1170         ASSERT_EQ(tbm_last_error, expected_last_result);
1171 }
1172
1173 TEST(tbm_bo_export_fd, work_flow_success_1)
1174 {
1175         int expected_key = -1;
1176         struct _tbm_bo bo;
1177         struct _tbm_bufmgr bufmgr;
1178         int key;
1179
1180         _init_test();
1181
1182         LIST_INITHEAD(&bufmgr.bo_list);
1183         gBufMgr = &bufmgr;
1184
1185         key = tbm_bo_export_fd(&bo);
1186
1187         ASSERT_EQ(key, expected_key);
1188 }
1189
1190 TEST(tbm_bo_export_fd, null_ptr_fail_1)
1191 {
1192         int expected_key = -1;
1193         int key;
1194
1195         _init_test();
1196
1197         key = tbm_bo_export_fd(NULL);
1198
1199         ASSERT_EQ(key, expected_key);
1200 }
1201
1202 /* tbm_bo_export() */
1203
1204 TEST(tbm_bo_export, work_flow_success_3)
1205 {
1206         struct _tbm_bo bo;
1207         struct _tbm_bufmgr bufmgr;
1208         struct _tbm_bufmgr_backend backend;
1209         int key;
1210
1211         _init_test();
1212
1213         LIST_INITHEAD(&bufmgr.bo_list);
1214         LIST_ADD(&bo.item_link, &bufmgr.bo_list);
1215         gBufMgr = &bufmgr;
1216         bo.bufmgr = &bufmgr;
1217         bufmgr.backend = &backend;
1218         backend.bo_export = ut_bo_export;
1219
1220         key = tbm_bo_export(&bo);
1221
1222         ASSERT_GT(key, 0);
1223 }
1224
1225 TEST(tbm_bo_export, work_flow_success_2)
1226 {
1227         tbm_error_e expected_last_result = TBM_BO_ERROR_EXPORT_FAILED;
1228         int expected_key = 0;
1229         struct _tbm_bo bo;
1230         struct _tbm_bufmgr bufmgr;
1231         struct _tbm_bufmgr_backend backend;
1232         int key;
1233
1234         _init_test();
1235
1236         LIST_INITHEAD(&bufmgr.bo_list);
1237         LIST_ADD(&bo.item_link, &bufmgr.bo_list);
1238         gBufMgr = &bufmgr;
1239         bo.bufmgr = &bufmgr;
1240         bufmgr.backend = &backend;
1241         backend.bo_export = ut_bo_export;
1242         UT_TBM_ERROR = 1;
1243
1244         key = tbm_bo_export(&bo);
1245
1246         ASSERT_EQ(key, expected_key);
1247         ASSERT_EQ(tbm_last_error, expected_last_result);
1248 }
1249
1250 TEST(tbm_bo_export, work_flow_success_1)
1251 {
1252         int expected_key = 0;
1253         struct _tbm_bo bo;
1254         struct _tbm_bufmgr bufmgr;
1255         int key;
1256
1257         _init_test();
1258
1259         LIST_INITHEAD(&bufmgr.bo_list);
1260         gBufMgr = &bufmgr;
1261
1262         key = tbm_bo_export(&bo);
1263
1264         ASSERT_EQ(key, expected_key);
1265 }
1266
1267 TEST(tbm_bo_export, null_ptr_fail_1)
1268 {
1269         int expected_key = 0;
1270         int key;
1271
1272         _init_test();
1273
1274         key = tbm_bo_export(NULL);
1275
1276         ASSERT_EQ(key, expected_key);
1277 }
1278
1279 /* tbm_bo_import_fd() */
1280
1281 TEST(tbm_bo_import_fd, work_flow_success_5)
1282 {
1283         int expected_flags = bo_ret_flags;
1284         int expected_ref_cnt = 1;
1285         struct _tbm_bufmgr bufmgr;
1286         struct _tbm_bufmgr_backend backend;
1287         struct _tbm_bo *actual_bo;
1288         struct _tbm_bo copy_bo;
1289
1290         _init_test();
1291
1292         gBufMgr = &bufmgr;
1293         memset(gBufMgr, 0, sizeof(bufmgr));
1294
1295         bufmgr.backend = &backend;
1296         bufmgr.bo_cnt = 1;
1297         backend.bo_import_fd = ut_bo_import_fd;
1298         LIST_INITHEAD(&bufmgr.bo_list);
1299         backend.bo_get_flags = ut_bo_get_flags;
1300
1301         actual_bo = tbm_bo_import_fd(&bufmgr, 1);
1302
1303         ASSERT_TRUE(actual_bo != NULL);
1304         copy_bo = *actual_bo;
1305         free(actual_bo);
1306         ASSERT_EQ(copy_bo.ref_cnt, expected_ref_cnt);
1307         ASSERT_EQ(copy_bo.flags, expected_flags);
1308         ASSERT_TRUE(bufmgr.bo_list.next != &bufmgr.bo_list);
1309         ASSERT_TRUE(bufmgr.bo_list.prev != &bufmgr.bo_list);
1310 }
1311
1312 TEST(tbm_bo_import_fd, work_flow_success_4)
1313 {
1314         int expected_flags = TBM_BO_DEFAULT;
1315         int expected_ref_cnt = 1;
1316         struct _tbm_bufmgr bufmgr;
1317         struct _tbm_bufmgr_backend backend;
1318         struct _tbm_bo *actual_bo;
1319         struct _tbm_bo copy_bo;
1320
1321         _init_test();
1322         gBufMgr = &bufmgr;
1323         memset(gBufMgr, 0, sizeof(bufmgr));
1324
1325         bufmgr.backend = &backend;
1326         bufmgr.bo_cnt = 1;
1327         backend.bo_import_fd = ut_bo_import_fd;
1328         LIST_INITHEAD(&bufmgr.bo_list);
1329         backend.bo_get_flags = NULL;
1330
1331         actual_bo = tbm_bo_import_fd(&bufmgr, 1);
1332
1333         ASSERT_TRUE(actual_bo != NULL);
1334         copy_bo = *actual_bo;
1335         free(actual_bo);
1336         ASSERT_EQ(copy_bo.ref_cnt, expected_ref_cnt);
1337         ASSERT_EQ(copy_bo.flags, expected_flags);
1338         ASSERT_TRUE(bufmgr.bo_list.next != &bufmgr.bo_list);
1339         ASSERT_TRUE(bufmgr.bo_list.prev != &bufmgr.bo_list);
1340 }
1341
1342 TEST(tbm_bo_import_fd, work_flow_success_3)
1343 {
1344         struct _tbm_bufmgr bufmgr;
1345         struct _tbm_bufmgr_backend backend;
1346         struct _tbm_bo expected_bo;
1347         int expected_ref_cnt;
1348
1349         _init_test();
1350
1351         gBufMgr = &bufmgr;
1352         memset(gBufMgr, 0, sizeof(bufmgr));
1353
1354         bufmgr.backend = &backend;
1355         bufmgr.bo_cnt = 1;
1356         backend.bo_import_fd = ut_bo_import_fd;
1357         LIST_INITHEAD(&bufmgr.bo_list);
1358         LIST_ADD(&expected_bo.item_link, &bufmgr.bo_list);
1359         expected_bo.priv = ret_bo;
1360         expected_bo.ref_cnt = 10;
1361         expected_ref_cnt = expected_bo.ref_cnt + 1;
1362
1363         struct _tbm_bo *actual_bo = tbm_bo_import_fd(&bufmgr, 1);
1364
1365         ASSERT_TRUE(actual_bo == &expected_bo);
1366         ASSERT_EQ(actual_bo->ref_cnt, expected_ref_cnt);
1367 }
1368
1369 TEST(tbm_bo_import_fd, work_flow_success_2)
1370 {
1371         struct _tbm_bo *expected = NULL;
1372         struct _tbm_bufmgr bufmgr;
1373         struct _tbm_bufmgr_backend backend;
1374         struct _tbm_bo *actual;
1375
1376         _init_test();
1377
1378         bufmgr.backend = &backend;
1379         bufmgr.bo_cnt = 1;
1380         backend.bo_import_fd = ut_bo_import_fd;
1381         TBM_BO_IMPORT_ERROR = 1;
1382
1383         actual = tbm_bo_import_fd(&bufmgr, 1);
1384
1385         ASSERT_TRUE(actual == expected);
1386 }
1387
1388 TEST(tbm_bo_import_fd, work_flow_success_1)
1389 {
1390         struct _tbm_bo *expected = NULL;
1391         struct _tbm_bufmgr bufmgr;
1392         struct _tbm_bo *actual;
1393
1394         _init_test();
1395
1396         CALLOC_ERROR = 1;
1397
1398         actual = tbm_bo_import_fd(&bufmgr, 1);
1399
1400         ASSERT_TRUE(actual == expected);
1401 }
1402
1403 TEST(tbm_bo_import_fd, null_ptr_fail_1)
1404 {
1405         struct _tbm_bo *expected = NULL;
1406         struct _tbm_bo *actual;
1407
1408         _init_test();
1409
1410         actual = tbm_bo_import_fd(NULL, 1);
1411
1412         ASSERT_TRUE(actual == expected);
1413 }
1414
1415 /* tbm_bo_import() */
1416
1417 TEST(tbm_bo_import, work_flow_success_5)
1418 {
1419         int expected_flags = bo_ret_flags;
1420         int expected_ref_cnt = 1;
1421         struct _tbm_bufmgr bufmgr;
1422         struct _tbm_bufmgr_backend backend;
1423         struct _tbm_bo *actual_bo;
1424         struct _tbm_bo copy_bo;
1425
1426         _init_test();
1427
1428         gBufMgr = &bufmgr;
1429         memset(gBufMgr, 0, sizeof(bufmgr));
1430
1431         bufmgr.backend = &backend;
1432         bufmgr.bo_cnt = 1;
1433         backend.bo_import = ut_bo_import;
1434         LIST_INITHEAD(&bufmgr.bo_list);
1435         backend.bo_get_flags = ut_bo_get_flags;
1436
1437         actual_bo = tbm_bo_import(&bufmgr, 1);
1438
1439         ASSERT_TRUE(actual_bo != NULL);
1440         copy_bo = *actual_bo;
1441         free(actual_bo);
1442         ASSERT_EQ(copy_bo.ref_cnt, expected_ref_cnt);
1443         ASSERT_EQ(copy_bo.flags, expected_flags);
1444         ASSERT_TRUE(bufmgr.bo_list.next != &bufmgr.bo_list);
1445         ASSERT_TRUE(bufmgr.bo_list.prev != &bufmgr.bo_list);
1446 }
1447
1448 TEST(tbm_bo_import, work_flow_success_4)
1449 {
1450         int expected_flags = TBM_BO_DEFAULT;
1451         int expected_ref_cnt = 1;
1452         struct _tbm_bufmgr bufmgr;
1453         struct _tbm_bufmgr_backend backend;
1454         struct _tbm_bo *actual_bo;
1455         struct _tbm_bo copy_bo;
1456
1457         _init_test();
1458
1459         gBufMgr = &bufmgr;
1460         memset(gBufMgr, 0, sizeof(bufmgr));
1461
1462         bufmgr.backend = &backend;
1463         bufmgr.bo_cnt = 1;
1464         backend.bo_import = ut_bo_import;
1465         LIST_INITHEAD(&bufmgr.bo_list);
1466         backend.bo_get_flags = NULL;
1467
1468         actual_bo = tbm_bo_import(&bufmgr, 1);
1469
1470         ASSERT_TRUE(actual_bo != NULL);
1471         copy_bo = *actual_bo;
1472         free(actual_bo);
1473         ASSERT_EQ(copy_bo.ref_cnt, expected_ref_cnt);
1474         ASSERT_EQ(copy_bo.flags, expected_flags);
1475         ASSERT_TRUE(bufmgr.bo_list.next != &bufmgr.bo_list);
1476         ASSERT_TRUE(bufmgr.bo_list.prev != &bufmgr.bo_list);
1477 }
1478
1479 TEST(tbm_bo_import, work_flow_success_3)
1480 {
1481         struct _tbm_bufmgr bufmgr;
1482         struct _tbm_bufmgr_backend backend;
1483         struct _tbm_bo expected_bo;
1484         int expected_ref_cnt;
1485         struct _tbm_bo *actual_bo;
1486
1487
1488         _init_test();
1489
1490         gBufMgr = &bufmgr;
1491         memset(gBufMgr, 0, sizeof(bufmgr));
1492
1493         bufmgr.backend = &backend;
1494         bufmgr.bo_cnt = 1;
1495         backend.bo_import = ut_bo_import;
1496         LIST_INITHEAD(&bufmgr.bo_list);
1497         LIST_ADD(&expected_bo.item_link, &bufmgr.bo_list);
1498         expected_bo.priv = ret_bo;
1499         expected_bo.ref_cnt = 10;
1500         expected_ref_cnt = expected_bo.ref_cnt + 1;
1501
1502         actual_bo = tbm_bo_import(&bufmgr, 1);
1503
1504         ASSERT_TRUE(actual_bo == &expected_bo);
1505         ASSERT_EQ(actual_bo->ref_cnt, expected_ref_cnt);
1506 }
1507
1508 TEST(tbm_bo_import, work_flow_success_2)
1509 {
1510         struct _tbm_bo *expected = NULL;
1511         struct _tbm_bufmgr bufmgr;
1512         struct _tbm_bufmgr_backend backend;
1513         struct _tbm_bo *actual;
1514
1515         _init_test();
1516
1517         bufmgr.backend = &backend;
1518         bufmgr.bo_cnt = 1;
1519         backend.bo_import = ut_bo_import;
1520         TBM_BO_IMPORT_ERROR = 1;
1521
1522         actual = tbm_bo_import(&bufmgr, 1);
1523
1524         ASSERT_TRUE(actual == expected);
1525 }
1526
1527 TEST(tbm_bo_import, work_flow_success_1)
1528 {
1529         struct _tbm_bo *expected = NULL;
1530         struct _tbm_bufmgr bufmgr;
1531         struct _tbm_bo *actual;
1532
1533         _init_test();
1534
1535         CALLOC_ERROR = 1;
1536
1537         actual = tbm_bo_import(&bufmgr, 1);
1538
1539         ASSERT_TRUE(actual == expected);
1540 }
1541
1542 TEST(tbm_bo_import, null_ptr_fail_1)
1543 {
1544         struct _tbm_bo *expected = NULL;
1545         struct _tbm_bo *actual;
1546
1547         _init_test();
1548
1549         actual = tbm_bo_import(NULL, 1);
1550
1551         ASSERT_TRUE(actual == expected);
1552 }
1553
1554 /* tbm_bo_alloc() */
1555
1556 TEST(tbm_bo_alloc, work_flow_success_3)
1557 {
1558         int flags = 6;
1559         int expected_ref_cnt = 1;
1560         struct _tbm_bo *not_expected_bo = NULL;
1561         struct _tbm_bufmgr bufmgr;
1562         struct _tbm_bufmgr_backend backend;
1563         struct _tbm_bo *actual_bo;
1564         struct _tbm_bo copy_bo;
1565
1566         _init_test();
1567
1568         gBufMgr = &bufmgr;
1569         memset(gBufMgr, 0, sizeof(bufmgr));
1570         bufmgr.backend = &backend;
1571         backend.bo_alloc = ut_bo_alloc;
1572         LIST_INITHEAD(&bufmgr.bo_list);
1573
1574         actual_bo = tbm_bo_alloc(&bufmgr, 1, flags);
1575
1576         ASSERT_TRUE(actual_bo != not_expected_bo);
1577         copy_bo = *actual_bo;
1578         free(actual_bo);
1579         ASSERT_EQ(copy_bo.flags, flags);
1580         ASSERT_EQ(copy_bo.ref_cnt, expected_ref_cnt);
1581         ASSERT_TRUE(copy_bo.priv == ret_bo);
1582         ASSERT_TRUE(bufmgr.bo_list.next != &bufmgr.bo_list);
1583         ASSERT_TRUE(bufmgr.bo_list.prev != &bufmgr.bo_list);
1584 }
1585
1586 TEST(tbm_bo_alloc, work_flow_success_2)
1587 {
1588         struct _tbm_bo *expected = NULL;
1589         tbm_error_e expected_last_error = TBM_BO_ERROR_BO_ALLOC_FAILED;
1590         struct _tbm_bufmgr bufmgr;
1591         struct _tbm_bufmgr_backend backend;
1592         struct _tbm_bo *actual;
1593
1594         _init_test();
1595
1596         gBufMgr = &bufmgr;
1597         memset(gBufMgr, 0, sizeof(bufmgr));
1598         LIST_INITHEAD(&gBufMgr->bo_list);
1599
1600         bufmgr.backend = &backend;
1601         backend.bo_alloc = ut_bo_alloc;
1602         TBM_BO_ALLOC_ERROR = 1;
1603
1604         actual = tbm_bo_alloc(&bufmgr, 1, 1);
1605
1606         ASSERT_TRUE(actual == expected);
1607         ASSERT_EQ(tbm_last_error, expected_last_error);
1608 }
1609
1610 TEST(tbm_bo_alloc, work_flow_success_1)
1611 {
1612         struct _tbm_bo *expected = NULL;
1613         struct _tbm_bufmgr bufmgr;
1614         tbm_error_e expected_last_error;
1615         struct _tbm_bo *actual;
1616
1617         _init_test();
1618
1619         gBufMgr = &bufmgr;
1620         memset(gBufMgr, 0, sizeof(bufmgr));
1621         LIST_INITHEAD(&gBufMgr->bo_list);
1622
1623         CALLOC_ERROR = 1;
1624         expected_last_error = TBM_BO_ERROR_HEAP_ALLOC_FAILED;
1625
1626         actual = tbm_bo_alloc(&bufmgr, 1, 1);
1627
1628         ASSERT_TRUE(actual == expected);
1629         ASSERT_EQ(tbm_last_error, expected_last_error);
1630 }
1631
1632 TEST(tbm_bo_alloc, null_int_fail_1)
1633 {
1634         struct _tbm_bo *expected = NULL;
1635         struct _tbm_bufmgr bufmgr;
1636         struct _tbm_bo *actual;
1637
1638         _init_test();
1639
1640         actual = tbm_bo_alloc(&bufmgr, 0, 1);
1641
1642         ASSERT_TRUE(actual == expected);
1643 }
1644
1645 TEST(tbm_bo_alloc, null_ptr_fail_1)
1646 {
1647         struct _tbm_bo *expected = NULL;
1648         struct _tbm_bo *actual;
1649
1650         _init_test();
1651
1652         actual = tbm_bo_alloc(NULL, 1, 1);
1653
1654         ASSERT_TRUE(actual == expected);
1655 }
1656
1657 /* tbm_bo_unref() */
1658
1659 TEST(tbm_bo_unref, work_flow_success_1)
1660 {
1661         struct _tbm_bo bo;
1662         struct _tbm_bufmgr bufmgr;
1663         int expected_ref_cnt;
1664
1665         _init_test();
1666
1667         LIST_INITHEAD(&bufmgr.bo_list);
1668         LIST_ADD(&bo.item_link, &bufmgr.bo_list);
1669         gBufMgr = &bufmgr;
1670         bo.ref_cnt = 10;
1671         expected_ref_cnt = bo.ref_cnt - 1;
1672
1673         tbm_bo_unref(&bo);
1674
1675         ASSERT_EQ(bo.ref_cnt, expected_ref_cnt);
1676 }
1677
1678 /* tbm_bo_ref() */
1679
1680 TEST(tbm_bo_ref, work_flow_success_3)
1681 {
1682         struct _tbm_bo bo;
1683         struct _tbm_bufmgr bufmgr;
1684         struct _tbm_bo *expected;
1685         struct _tbm_bo *actual;
1686
1687         _init_test();
1688
1689         LIST_INITHEAD(&bufmgr.bo_list);
1690         LIST_ADD(&bo.item_link, &bufmgr.bo_list);
1691         gBufMgr = &bufmgr;
1692         bo.ref_cnt = 1;
1693         int expected_ref_cnt = bo.ref_cnt + 1;
1694         expected = &bo;
1695
1696         actual = tbm_bo_ref(&bo);
1697
1698         ASSERT_TRUE(actual == expected);
1699         ASSERT_EQ(bo.ref_cnt, expected_ref_cnt);
1700 }
1701
1702 TEST(tbm_bo_ref, work_flow_success_2)
1703 {
1704         struct _tbm_bo *expected = NULL;
1705         struct _tbm_bo bo;
1706         struct _tbm_bufmgr bufmgr;
1707         struct _tbm_bo *actual;
1708
1709         _init_test();
1710
1711         LIST_INITHEAD(&bufmgr.bo_list);
1712         gBufMgr = &bufmgr;
1713
1714         actual = tbm_bo_ref(&bo);
1715
1716         ASSERT_TRUE(actual == expected);
1717 }
1718
1719 TEST(tbm_bo_ref, work_flow_success_1)
1720 {
1721         struct _tbm_bo *expected = NULL;
1722         struct _tbm_bo *actual;
1723
1724         _init_test();
1725
1726         actual = tbm_bo_ref(NULL);
1727
1728         ASSERT_TRUE(actual == expected);
1729 }
1730
1731 /* tbm_bo_size() */
1732
1733 TEST(tbm_bo_size, work_flow_success_3)
1734 {
1735         int not_expected = 0;
1736         struct _tbm_bo bo;
1737         struct _tbm_bufmgr bufmgr;
1738         struct _tbm_bufmgr_backend backend;
1739         int actual;
1740
1741         _init_test();
1742
1743         LIST_INITHEAD(&bufmgr.bo_list);
1744         LIST_ADD(&bo.item_link, &bufmgr.bo_list);
1745         gBufMgr = &bufmgr;
1746         backend.bo_size = ut_bo_size;
1747         bufmgr.backend = &backend;
1748         bo.bufmgr = &bufmgr;
1749
1750         actual = tbm_bo_size(&bo);
1751
1752         ASSERT_TRUE(actual != not_expected);
1753 }
1754
1755 TEST(tbm_bo_size, work_flow_success_2)
1756 {
1757         int expected = 0;
1758         struct _tbm_bo bo;
1759         struct _tbm_bufmgr bufmgr;
1760         int actual;
1761
1762         _init_test();
1763
1764         LIST_INITHEAD(&bufmgr.bo_list);
1765         gBufMgr = &bufmgr;
1766
1767         actual = tbm_bo_size(&bo);
1768
1769         ASSERT_EQ(actual, expected);
1770 }
1771
1772 TEST(tbm_bo_size, work_flow_success_1)
1773 {
1774         int expected = 0;
1775         int actual ;
1776
1777         _init_test();
1778
1779         actual = tbm_bo_size(NULL);
1780
1781         ASSERT_EQ(actual, expected);
1782 }