@@ -30,8 +30,52 @@ static void test_brick_core_simple_lifecycle(void)
30
30
{
31
31
struct pg_error * error = NULL ;
32
32
struct pg_brick * brick ;
33
- struct pg_brick_config * config = pg_brick_config_new ("mybrick" , 2 , 2 ,
34
- PG_MULTIPOLE );
33
+ struct pg_brick_config * config = pg_brick_config_new ("mybrick" , 2 , 2 , PG_MULTIPOLE );
34
+ struct pg_brick_config * config1 = pg_brick_config_new ("mybrick" , 2 , 2 , PG_MONOPOLE );
35
+ struct pg_brick_config * config2 = pg_brick_config_new ("mybrick" , UINT16_MAX , UINT16_MAX , PG_MULTIPOLE );
36
+
37
+ brick = pg_brick_new ("nop" , config1 , & error );
38
+ g_assert (!brick );
39
+ g_assert (error );
40
+ g_assert (error -> message );
41
+ g_assert_cmpstr (error -> message , = = , "A 'PG_MONOPOLE' cannot have more than one neibour per side" );
42
+ pg_error_free (error );
43
+ error = NULL ;
44
+
45
+ brick = pg_brick_new ("nop" , config2 , & error );
46
+ g_assert (!brick );
47
+ g_assert (error );
48
+ g_assert (error -> message );
49
+ g_assert_cmpstr (error -> message , = = , "A 'PG_MULTIPOLE' cannot have more than 65535 edge on PG_WEST_SIDE" );
50
+ pg_error_free (error );
51
+ error = NULL ;
52
+
53
+ brick = pg_brick_new (NULL , NULL , & error );
54
+ g_assert (!brick );
55
+ g_assert (error );
56
+ g_assert (error -> message );
57
+ g_assert_cmpstr (error -> message , = = , "Brick config not set" );
58
+ pg_error_free (error );
59
+ error = NULL ;
60
+
61
+ brick = pg_brick_new (NULL , config , & error );
62
+ g_assert (!brick );
63
+ g_assert (error );
64
+ g_assert (error -> message );
65
+ g_assert_cmpstr (error -> message , = = , "Brick name not set" );
66
+ pg_error_free (error );
67
+ error = NULL ;
68
+
69
+ pg_brick_decref (brick , & error );
70
+ g_assert (error );
71
+ g_assert (error -> message );
72
+ g_assert_cmpstr (error -> message , = = , "NULL brick" );
73
+ pg_error_free (error );error = NULL ;
74
+
75
+ g_assert (pg_brick_reset (brick ,& error ) < 0 );
76
+ g_assert (error );
77
+ pg_error_free (error );
78
+ error = NULL ;
35
79
36
80
brick = pg_brick_new ("foo" , config , & error );
37
81
g_assert (!brick );
@@ -44,9 +88,11 @@ static void test_brick_core_simple_lifecycle(void)
44
88
brick = pg_brick_new ("nop" , config , & error );
45
89
g_assert (brick );
46
90
g_assert (!error );
91
+ printf ("brick refcount is %ld\n" ,brick -> refcount );
47
92
48
93
pg_brick_decref (brick , & error );
49
94
g_assert (!error );
95
+ printf ("brick refcount is %ld\n" ,brick -> refcount );
50
96
51
97
brick = pg_brick_decref (NULL , & error );
52
98
g_assert (!brick );
@@ -107,6 +153,11 @@ static void test_brick_core_link(void)
107
153
g_assert (middle_brick );
108
154
g_assert (!error );
109
155
156
+ g_assert (pg_brick_reset (middle_brick ,& error )!= 0 );
157
+ g_assert (error );
158
+ pg_error_free (error );
159
+ error = NULL ;
160
+
110
161
east_brick = pg_brick_new ("nop" , config , & error );
111
162
g_assert (east_brick );
112
163
g_assert (!error );
@@ -180,6 +231,22 @@ static void test_brick_core_unlink_edge(void)
180
231
g_assert (ret == 0 );
181
232
g_assert (!error );
182
233
234
+ ret = pg_brick_link (west_brick , west_brick , & error );
235
+ g_assert (ret == -1 );
236
+ g_assert (error );
237
+ g_assert (error -> message );
238
+ g_assert_cmpstr (error -> message , = = , "Can not link a brick to itself" );
239
+ pg_error_free (error );
240
+ error = NULL ;
241
+
242
+ ret = pg_brick_link (NULL , west_brick , & error );
243
+ g_assert (ret == -1 );
244
+ g_assert (error );
245
+ g_assert (error -> message );
246
+ g_assert_cmpstr (error -> message , = = , "Node is not valid" );
247
+ pg_error_free (error );
248
+ error = NULL ;
249
+
183
250
ret = pg_brick_link (middle_brick , east_brick , & error );
184
251
g_assert (ret == 0 );
185
252
g_assert (!error );
@@ -199,6 +266,14 @@ static void test_brick_core_unlink_edge(void)
199
266
g_assert (error );
200
267
pg_error_free (error );
201
268
error = NULL ;
269
+ g_assert (pg_brick_unlink_edge (east_brick , NULL , & error ) == -1 );
270
+ g_assert (error );
271
+ pg_error_free (error );
272
+ error = NULL ;
273
+ g_assert (pg_brick_unlink_edge (NULL , west_brick , & error ) == -1 );
274
+ g_assert (error );
275
+ pg_error_free (error );
276
+ error = NULL ;
202
277
203
278
g_assert (!pg_brick_unlink_edge (west_brick , middle_brick , & error ));
204
279
refcount = pg_brick_refcount (west_brick );
@@ -628,9 +703,19 @@ static void test_brick_sanity_check_expected(struct pg_brick *brick,
628
703
629
704
static void test_brick_core_verify_multiple_link (void )
630
705
{
631
- struct pg_brick * west_brick , * middle_brick , * east_brick ;
706
+ struct pg_brick * west_brick , * middle_brick , * east_brick ,
707
+ * west_brick1 , * middle_brick1 , * east_brick1 ,
708
+ * west_brick2 , * middle_brick2 , * east_brick2 ,
709
+ * west_brick3 , * middle_brick3 , * east_brick3 ;
710
+
632
711
struct pg_brick_config * config = pg_brick_config_new ("mybrick" , 4 , 4 ,
633
712
PG_MULTIPOLE );
713
+ struct pg_brick_config * config1 = pg_brick_config_new ("mybrick" , 1 , 1 ,
714
+ PG_DIPOLE );
715
+ struct pg_brick_config * config2 = pg_brick_config_new ("mybrick" , 1 , 1 ,
716
+ PG_MONOPOLE );
717
+ struct pg_brick_config * config3 = pg_brick_config_new ("mybrick" , 1 , 1 ,
718
+ 4 );
634
719
uint32_t links_count ;
635
720
struct pg_error * error = NULL ;
636
721
@@ -641,6 +726,27 @@ static void test_brick_core_verify_multiple_link(void)
641
726
east_brick = pg_brick_new ("nop" , config , & error );
642
727
g_assert (!error );
643
728
729
+ west_brick1 = pg_brick_new ("nop" , config1 , & error );
730
+ g_assert (!error );
731
+ middle_brick1 = pg_brick_new ("nop" , config1 , & error );
732
+ g_assert (!error );
733
+ east_brick1 = pg_brick_new ("nop" , config1 , & error );
734
+ g_assert (!error );
735
+
736
+ west_brick2 = pg_brick_new ("nop" , config2 , & error );
737
+ g_assert (!error );
738
+ middle_brick2 = pg_brick_new ("nop" , config2 , & error );
739
+ g_assert (!error );
740
+ east_brick2 = pg_brick_new ("nop" , config2 , & error );
741
+ g_assert (!error );
742
+
743
+ west_brick3 = pg_brick_new ("nop" , config3 , & error );
744
+ g_assert (!error );
745
+ middle_brick3 = pg_brick_new ("nop" , config3 , & error );
746
+ g_assert (!error );
747
+ east_brick3 = pg_brick_new ("nop" , config3 , & error );
748
+ g_assert (!error );
749
+
644
750
/* create a few links */
645
751
pg_brick_link (west_brick , middle_brick , & error );
646
752
g_assert (!error );
@@ -652,13 +758,61 @@ static void test_brick_core_verify_multiple_link(void)
652
758
g_assert (!error );
653
759
pg_brick_link (middle_brick , east_brick , & error );
654
760
g_assert (!error );
761
+ pg_brick_link (middle_brick1 , east_brick1 , & error );
762
+ g_assert (!error );
763
+ pg_brick_link (middle_brick2 , east_brick2 , & error );
764
+ g_assert (!error );
765
+
766
+ pg_brick_link (middle_brick1 , west_brick1 , & error );
767
+ g_assert (error );
768
+ pg_error_free (error );
769
+ error = NULL ;
770
+
771
+ pg_brick_link (middle_brick2 , west_brick2 , & error );
772
+ g_assert (error );
773
+ pg_error_free (error );
774
+ error = NULL ;
655
775
776
+ pg_brick_link (middle_brick3 , west_brick3 , & error );
777
+ g_assert (error );
778
+ pg_error_free (error );
779
+ error = NULL ;
780
+
781
+ pg_brick_link (west_brick3 , middle_brick3 , & error );
782
+ g_assert (error );
783
+ pg_error_free (error );
784
+ error = NULL ;
785
+
656
786
/* sanity checks */
657
787
test_brick_sanity_check (west_brick );
658
788
test_brick_sanity_check (middle_brick );
659
789
test_brick_sanity_check (east_brick );
660
790
661
- /* check the link count */
791
+ /* check the link count */
792
+ links_count = pg_brick_links_count_get (NULL , west_brick , & error );
793
+ g_assert (error );
794
+ g_assert (links_count == (uint32_t ) -1 );
795
+ g_assert (error -> message );
796
+ g_assert_cmpstr (error -> message , = = , "brick is NULL" );
797
+ pg_error_free (error );
798
+ error = NULL ;
799
+
800
+ links_count = pg_brick_links_count_get (middle_brick3 , west_brick3 , & error );
801
+ g_assert (error );
802
+ g_assert (links_count == (uint32_t )-1 );
803
+ g_assert (error -> message );
804
+ g_assert_cmpstr (error -> message , = = , "brick config type is unknown" );
805
+ pg_error_free (error );
806
+ error = NULL ;
807
+
808
+ links_count = pg_brick_links_count_get (east_brick3 , west_brick3 , & error );
809
+ g_assert (error );
810
+ g_assert (links_count == (uint32_t )-1 );
811
+ g_assert (error -> message );
812
+ g_assert_cmpstr (error -> message , = = , "brick config type is unknown" );
813
+ pg_error_free (error );
814
+ error = NULL ;
815
+
662
816
links_count = pg_brick_links_count_get (west_brick , west_brick , & error );
663
817
g_assert (!error );
664
818
g_assert (links_count == 0 );
@@ -694,6 +848,22 @@ static void test_brick_core_verify_multiple_link(void)
694
848
g_assert (!error );
695
849
g_assert (links_count == 3 );
696
850
851
+ links_count = pg_brick_links_count_get (middle_brick1 ,east_brick1 , & error );
852
+ g_assert (!error );
853
+ g_assert (links_count == 1 );
854
+
855
+ links_count = pg_brick_links_count_get (middle_brick2 , east_brick2 , & error );
856
+ g_assert (!error );
857
+ g_assert (links_count == 1 );
858
+
859
+ links_count = pg_brick_links_count_get (west_brick2 , middle_brick2 , & error );
860
+ g_assert (!error );
861
+ g_assert (links_count == 0 );
862
+
863
+ links_count = pg_brick_links_count_get (east_brick1 , east_brick1 , & error );
864
+ g_assert (!error );
865
+ g_assert (links_count == 0 );
866
+
697
867
/* unlink the west brick */
698
868
pg_brick_unlink (west_brick , & error );
699
869
@@ -821,13 +991,23 @@ static void test_brick_core_verify_re_link(void)
821
991
test_brick_sanity_check_expected (f , 1 , 1 );
822
992
test_brick_sanity_check_expected (a , 1 , 0 );
823
993
994
+ pg_brick_chained_links (& e ,v ,NULL );
995
+ g_assert (e );
996
+ pg_error_free (e );
997
+ e = NULL ;
998
+
824
999
/* Unlink f */
825
1000
pg_brick_unlink (f , & e );
826
1001
g_assert (!e );
827
1002
test_brick_sanity_check_expected (v , 0 , 0 );
828
1003
test_brick_sanity_check_expected (f , 0 , 0 );
829
1004
test_brick_sanity_check_expected (a , 0 , 0 );
830
1005
1006
+ pg_brick_unlink (NULL , & e );
1007
+ g_assert (e );
1008
+ pg_error_free (e );
1009
+ e = NULL ;
1010
+
831
1011
/* Link v and s */
832
1012
pg_brick_link (v , s , & e );
833
1013
g_assert (!e );
0 commit comments