1
   2
   3
   4
   5
   6
   7
   8
   9
  10
  11
  12
  13
  14
  15
  16
  17
  18
  19
  20
  21
  22
  23
  24
  25
  26
  27
  28
  29
  30
  31
  32
  33
  34
  35
  36
  37
  38
  39
  40
  41
  42
  43
  44
  45
  46
  47
  48
  49
  50
  51
  52
  53
  54
  55
  56
  57
  58
  59
  60
  61
  62
  63
  64
  65
  66
  67
  68
  69
  70
  71
  72
  73
  74
  75
  76
  77
  78
  79
  80
  81
  82
  83
  84
  85
  86
  87
  88
  89
  90
  91
  92
  93
  94
  95
  96
  97
  98
  99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 135
 136
 137
 138
 139
 140
 141
 142
 143
 144
 145
 146
 147
 148
 149
 150
 151
 152
 153
 154
 155
 156
 157
 158
 159
 160
 161
 162
 163
 164
 165
 166
 167
 168
 169
 170
 171
 172
 173
 174
 175
 176
 177
 178
 179
 180
 181
 182
 183
 184
 185
 186
 187
 188
 189
 190
 191
 192
 193
 194
 195
 196
 197
 198
 199
 200
 201
 202
 203
 204
 205
 206
 207
 208
 209
 210
 211
 212
 213
 214
 215
 216
 217
 218
 219
 220
 221
 222
 223
 224
 225
 226
 227
 228
 229
 230
 231
 232
 233
 234
 235
 236
 237
 238
 239
 240
 241
 242
 243
 244
 245
 246
 247
 248
 249
 250
 251
 252
 253
 254
 255
 256
 257
 258
 259
 260
 261
 262
 263
 264
 265
 266
 267
 268
 269
 270
 271
 272
 273
 274
 275
 276
 277
 278
 279
 280
 281
 282
 283
 284
 285
 286
 287
 288
 289
 290
 291
 292
 293
 294
 295
 296
 297
 298
 299
 300
 301
 302
 303
 304
 305
 306
 307
 308
 309
 310
 311
 312
 313
 314
 315
 316
 317
 318
 319
 320
 321
 322
 323
 324
 325
 326
 327
 328
 329
 330
 331
 332
 333
 334
 335
 336
 337
 338
 339
 340
 341
 342
 343
 344
 345
 346
 347
 348
 349
 350
 351
 352
 353
 354
 355
 356
 357
 358
 359
 360
 361
 362
 363
 364
 365
 366
 367
 368
 369
 370
 371
 372
 373
 374
 375
 376
 377
 378
 379
 380
 381
 382
 383
 384
 385
 386
 387
 388
 389
 390
 391
 392
 393
 394
 395
 396
 397
 398
 399
 400
 401
 402
 403
 404
 405
 406
 407
 408
 409
 410
 411
 412
 413
 414
 415
 416
 417
 418
 419
 420
 421
 422
 423
 424
 425
 426
 427
 428
 429
 430
 431
 432
 433
 434
 435
 436
 437
 438
 439
 440
 441
 442
 443
 444
 445
 446
 447
 448
 449
 450
 451
 452
 453
 454
 455
 456
 457
 458
 459
 460
 461
 462
 463
 464
 465
 466
 467
 468
 469
 470
 471
 472
 473
 474
 475
 476
 477
 478
 479
 480
 481
 482
 483
 484
 485
 486
 487
 488
 489
 490
 491
 492
 493
 494
 495
 496
 497
 498
 499
 500
 501
 502
 503
 504
 505
 506
 507
 508
 509
 510
 511
 512
 513
 514
 515
 516
 517
 518
 519
 520
 521
 522
 523
 524
 525
 526
 527
 528
 529
 530
 531
 532
 533
 534
 535
 536
 537
 538
 539
 540
 541
 542
 543
 544
 545
 546
 547
 548
 549
 550
 551
 552
 553
 554
 555
 556
 557
 558
 559
 560
 561
 562
 563
 564
 565
 566
 567
 568
 569
 570
 571
 572
 573
 574
 575
 576
 577
 578
 579
 580
 581
 582
 583
 584
 585
 586
 587
 588
 589
 590
 591
 592
 593
 594
 595
 596
 597
 598
 599
 600
 601
 602
 603
 604
 605
 606
 607
 608
 609
 610
 611
 612
 613
 614
 615
 616
 617
 618
 619
 620
 621
 622
 623
 624
 625
 626
 627
 628
 629
 630
 631
 632
 633
 634
 635
 636
 637
 638
 639
 640
 641
 642
 643
 644
 645
 646
 647
 648
 649
 650
 651
 652
 653
 654
 655
 656
 657
 658
 659
 660
 661
 662
 663
 664
 665
 666
 667
 668
 669
 670
 671
 672
 673
 674
 675
 676
 677
 678
 679
 680
 681
 682
 683
 684
 685
 686
 687
 688
 689
 690
 691
 692
 693
 694
 695
 696
 697
 698
 699
 700
 701
 702
 703
 704
 705
 706
 707
 708
 709
 710
 711
 712
 713
 714
 715
 716
 717
 718
 719
 720
 721
 722
 723
 724
 725
 726
 727
 728
 729
 730
 731
 732
 733
 734
 735
 736
 737
 738
 739
 740
 741
 742
 743
 744
 745
 746
 747
 748
 749
 750
 751
 752
 753
 754
 755
 756
 757
 758
 759
 760
 761
 762
 763
 764
 765
 766
 767
 768
 769
 770
 771
 772
 773
 774
 775
 776
 777
 778
 779
 780
 781
 782
 783
 784
 785
 786
 787
 788
 789
 790
 791
 792
 793
 794
 795
 796
 797
 798
 799
 800
 801
 802
 803
 804
 805
 806
 807
 808
 809
 810
 811
 812
 813
 814
 815
 816
 817
 818
 819
 820
 821
 822
 823
 824
 825
 826
 827
 828
 829
 830
 831
 832
 833
 834
 835
 836
 837
 838
 839
 840
 841
 842
 843
 844
 845
 846
 847
 848
 849
 850
 851
 852
 853
 854
 855
 856
 857
 858
 859
 860
 861
 862
 863
 864
 865
 866
 867
 868
 869
 870
 871
 872
 873
 874
 875
 876
 877
 878
 879
 880
 881
 882
 883
 884
 885
 886
 887
 888
 889
 890
 891
 892
 893
 894
 895
 896
 897
 898
 899
 900
 901
 902
 903
 904
 905
 906
 907
 908
 909
 910
 911
 912
 913
 914
 915
 916
 917
 918
 919
 920
 921
 922
 923
 924
 925
 926
 927
 928
 929
 930
 931
 932
 933
 934
 935
 936
 937
 938
 939
 940
 941
 942
 943
 944
 945
 946
 947
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
/* *****************************************************************
    MESQUITE -- The Mesh Quality Improvement Toolkit

    Copyright 2007 Sandia National Laboratories.  Developed at the
    University of Wisconsin--Madison under SNL contract number
    624796.  The U.S. Government and the University of Wisconsin
    retain certain rights to this software.

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
    version 2.1 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public License
    (lgpl.txt) along with this library; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

    (2007) [email protected]

  ***************************************************************** */

/** \file ArrayMeshTest.cpp
 *  \brief
 *  \author Jason Kraftcheck
 */

#include "Mesquite.hpp"
#include "ArrayMesh.hpp"
#include "MsqVertex.hpp"
#include "MsqError.hpp"
#include "UnitUtil.hpp"

using namespace MBMesquite;

class ArrayMeshTest : public CppUnit::TestFixture
{
  private:
    CPPUNIT_TEST_SUITE( ArrayMeshTest );

    CPPUNIT_TEST( test_get_geometric_dimension );
    CPPUNIT_TEST( test_get_all_elements );
    CPPUNIT_TEST( test_get_all_vertices );
    CPPUNIT_TEST( test_get_all_vertices_one_based );
    CPPUNIT_TEST( test_vertex_iterator );
    CPPUNIT_TEST( test_vertex_iterator_one_based );
    CPPUNIT_TEST( test_element_iterator );
    CPPUNIT_TEST( test_vertices_get_fixed_flag );
    CPPUNIT_TEST( test_vertices_get_coordinates );
    CPPUNIT_TEST( test_vertices_get_coordinates_two_d );
    CPPUNIT_TEST( test_vertices_get_coordinates_one_based );
    CPPUNIT_TEST( test_vertex_set_coordinates );
    CPPUNIT_TEST( test_vertex_set_coordinates_two_d );
    CPPUNIT_TEST( test_vertex_set_coordinates_one_based );
    CPPUNIT_TEST( test_vertex_set_byte );
    CPPUNIT_TEST( test_vertices_set_byte );
    CPPUNIT_TEST( test_vertices_get_attached_elements );
    CPPUNIT_TEST( test_vertices_get_attached_elements_one_based );
    CPPUNIT_TEST( test_elements_get_attached_vertices );
    CPPUNIT_TEST( test_elements_get_topologies );

    CPPUNIT_TEST( test_vertices_get_attached_elements_mixed );
    CPPUNIT_TEST( test_vertices_get_attached_elements_mixed_one_based );
    CPPUNIT_TEST( test_elements_get_attached_vertices_mixed );
    CPPUNIT_TEST( test_elements_get_attached_vertices_mixed_one_based );
    CPPUNIT_TEST( test_elements_get_topologies_mixed );

    CPPUNIT_TEST( test_vertex_readonly_tag_data );
    CPPUNIT_TEST( test_vertex_readonly_tag_data_one_based );
    CPPUNIT_TEST( test_element_readonly_tag_data );
    CPPUNIT_TEST( test_vertex_writable_tag_data );
    CPPUNIT_TEST( test_vertex_writable_tag_data_one_based );
    CPPUNIT_TEST( test_element_writable_tag_data );
    CPPUNIT_TEST( test_vertex_owned_tag_data );
    CPPUNIT_TEST( test_vertex_owned_tag_data_one_based );
    CPPUNIT_TEST( test_element_owned_tag_data );
    CPPUNIT_TEST( test_delete_tag );

    CPPUNIT_TEST_SUITE_END();

    ArrayMesh *zeroBased3D, *oneBased3D, *zeroBased2D, *oneBased2D;
    ArrayMesh *mixedZeroBased, *mixedOneBased;
    double *zeroBased3Dcoords, *oneBased3Dcoords, *zeroBased2Dcoords, *oneBased2Dcoords;
    double *mixedZeroBasedCoords, *mixedOneBasedCoords;

  public:
    void setUp();
    void tearDown();

    void test_get_geometric_dimension();
    void test_get_all_elements();
    void test_get_all_vertices();
    void test_get_all_vertices_one_based();
    void test_vertex_iterator();
    void test_vertex_iterator_one_based();
    void test_element_iterator();
    void test_vertices_get_fixed_flag();
    void test_vertices_get_coordinates();
    void test_vertices_get_coordinates_two_d();
    void test_vertices_get_coordinates_one_based();
    void test_vertex_set_coordinates();
    void test_vertex_set_coordinates_two_d();
    void test_vertex_set_coordinates_one_based();
    void test_vertex_set_byte();
    void test_vertices_set_byte();
    void test_vertices_get_attached_elements();
    void test_vertices_get_attached_elements_one_based();
    void test_elements_get_attached_vertices();
    void test_elements_get_topologies();

    void test_vertices_get_attached_elements_mixed();
    void test_vertices_get_attached_elements_mixed_one_based();
    void test_elements_get_attached_vertices_mixed();
    void test_elements_get_attached_vertices_mixed_one_based();
    void test_elements_get_topologies_mixed();

    enum TagEntType
    {
        VERTEX,
        ONE_BASED_VERTEX,
        ELEMENT
    };
    enum TagStorage
    {
        READONLY,
        WRITABLE,
        OWNED
    };
    void test_tag_data( TagEntType type, TagStorage storage );
    void test_readonly_tag_data( TagEntType type )
    {
        test_tag_data( type, READONLY );
    }
    void test_writable_tag_data( TagEntType type )
    {
        test_tag_data( type, WRITABLE );
    }
    void test_owned_tag_data( TagEntType type )
    {
        test_tag_data( type, OWNED );
    }

    void test_vertex_readonly_tag_data()
    {
        test_readonly_tag_data( VERTEX );
    }
    void test_vertex_readonly_tag_data_one_based()
    {
        test_readonly_tag_data( ONE_BASED_VERTEX );
    }
    void test_element_readonly_tag_data()
    {
        test_readonly_tag_data( ELEMENT );
    }
    void test_vertex_writable_tag_data()
    {
        test_writable_tag_data( VERTEX );
    }
    void test_vertex_writable_tag_data_one_based()
    {
        test_writable_tag_data( ONE_BASED_VERTEX );
    }
    void test_element_writable_tag_data()
    {
        test_writable_tag_data( ELEMENT );
    }
    void test_vertex_owned_tag_data()
    {
        test_owned_tag_data( VERTEX );
    }
    void test_vertex_owned_tag_data_one_based()
    {
        test_owned_tag_data( ONE_BASED_VERTEX );
    }
    void test_element_owned_tag_data()
    {
        test_owned_tag_data( ELEMENT );
    }
    void test_delete_tag();
};

CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( ArrayMeshTest, "ArrayMeshTest" );
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( ArrayMeshTest, "Unit" );

/* Mesh:

   0---------1----------2
   |         |          |
   |    0    |    1     |
   |         |          |
   |         |          |
   3---------4----------5
   |         |          |
   Y    2    |    3     |
   ^         |          |
   |         |          |
   6-->X-----7----------8

 Z = -2

*/
const double coords_2d[] = { 0, 2, 1, 2, 2, 2, 0, 1, 1, 1, 2, 1, 0, 0, 1, 0, 2, 0 };
const double coords_3d[] = { 0, 2, -2, 1, 2, -2, 2, 2, -2, 0, 1, -2, 1, 1, -2, 2, 1, -2, 0, 0, -2, 1, 0, -2, 2, 0, -2 };
const unsigned long conn_zero_based[] = { 3, 4, 1, 0, 4, 5, 2, 1, 6, 7, 4, 3, 7, 8, 5, 4 };
const unsigned long conn_one_based[]  = { 4, 5, 2, 1, 5, 6, 3, 2, 7, 8, 5, 4, 8, 9, 6, 5 };

const int fixed[] = { 1, 1, 1, 1, 0, 1, 1, 1, 1 };

/* Mixed mesh
 *
 *   0-------1-------2-------3
 *   |       | \  2  |       |
 *   |   0   |   \   |   3   |
 *   |       | 1   \ |       |
 *   7-------6-------5-------4
 */
const double mixed_coords[]             = { 0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 2.0, 1.0, 0.0, 3.0, 1.0, 0.0,
                                3.0, 0.0, 0.0, 2.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
const unsigned long mixed_conn_zero[]   = { 7, 6, 1, 0, 6, 5, 1, 2, 1, 5, 5, 4, 3, 2 };
const unsigned long mixed_conn_one[]    = { 8, 7, 2, 1, 7, 6, 2, 3, 2, 6, 6, 5, 4, 3 };
const EntityTopology mixed_types[]      = { QUADRILATERAL, TRIANGLE, TRIANGLE, QUADRILATERAL };
const unsigned long conn_offsets_zero[] = { 0, 4, 7, 10, 14 };

void ArrayMeshTest::setUp()<--- The function 'setUp' is never used.
{
    zeroBased3Dcoords    = new double[27];<--- Possible leak in public function. The pointer 'zeroBased3Dcoords' is not deallocated before it is allocated.
    oneBased3Dcoords     = new double[27];
    zeroBased2Dcoords    = new double[18];
    oneBased2Dcoords     = new double[18];
    mixedZeroBasedCoords = new double[24];
    mixedOneBasedCoords  = new double[24];
    memcpy( zeroBased3Dcoords, coords_3d, 27 * sizeof( double ) );
    memcpy( oneBased3Dcoords, coords_3d, 27 * sizeof( double ) );
    memcpy( zeroBased2Dcoords, coords_2d, 18 * sizeof( double ) );
    memcpy( oneBased2Dcoords, coords_2d, 18 * sizeof( double ) );
    memcpy( mixedZeroBasedCoords, mixed_coords, 24 * sizeof( double ) );
    memcpy( mixedOneBasedCoords, mixed_coords, 24 * sizeof( double ) );
    zeroBased3D = new ArrayMesh( 3, 9, zeroBased3Dcoords, fixed, 4, QUADRILATERAL, conn_zero_based, false );
    oneBased3D  = new ArrayMesh( 3, 9, oneBased3Dcoords, fixed, 4, QUADRILATERAL, conn_one_based, true );
    zeroBased2D = new ArrayMesh( 2, 9, zeroBased2Dcoords, fixed, 4, QUADRILATERAL, conn_zero_based, false );
    oneBased2D  = new ArrayMesh( 2, 9, oneBased2Dcoords, fixed, 4, QUADRILATERAL, conn_one_based, true );
    mixedZeroBased =
        new ArrayMesh( 3, 8, mixedZeroBasedCoords, fixed, 4, mixed_types, mixed_conn_zero, conn_offsets_zero, false );
    mixedOneBased = new ArrayMesh( 3, 8, mixedOneBasedCoords, fixed, 4, mixed_types, mixed_conn_one, NULL, true );
}

void ArrayMeshTest::tearDown()<--- The function 'tearDown' is never used.
{
    delete zeroBased3D;
    delete oneBased3D;
    delete zeroBased2D;
    delete oneBased2D;
    delete mixedZeroBased;
    delete mixedOneBased;
    delete[] zeroBased3Dcoords;
    delete[] oneBased3Dcoords;
    delete[] zeroBased2Dcoords;
    delete[] oneBased2Dcoords;
    delete[] mixedZeroBasedCoords;
    delete[] mixedOneBasedCoords;
}

void ArrayMeshTest::test_get_geometric_dimension()
{
    MsqPrintError err( std::cerr );
    CPPUNIT_ASSERT_EQUAL( 2, zeroBased2D->get_geometric_dimension( err ) );
    CPPUNIT_ASSERT_EQUAL( 2, oneBased2D->get_geometric_dimension( err ) );
    CPPUNIT_ASSERT_EQUAL( 3, zeroBased3D->get_geometric_dimension( err ) );
    CPPUNIT_ASSERT_EQUAL( 3, oneBased3D->get_geometric_dimension( err ) );
}

void ArrayMeshTest::test_get_all_elements()
{
    MsqPrintError err( std::cerr );
    std::vector< Mesh::ElementHandle > list;
    zeroBased3D->get_all_elements( list, err );
    CPPUNIT_ASSERT( !err );
    CPPUNIT_ASSERT_EQUAL( (size_t)4, list.size() );
    CPPUNIT_ASSERT_EQUAL( (size_t)0, (size_t)list[0] );
    CPPUNIT_ASSERT_EQUAL( (size_t)1, (size_t)list[1] );
    CPPUNIT_ASSERT_EQUAL( (size_t)2, (size_t)list[2] );
    CPPUNIT_ASSERT_EQUAL( (size_t)3, (size_t)list[3] );
}

void ArrayMeshTest::test_get_all_vertices()
{
    MsqPrintError err( std::cerr );
    std::vector< Mesh::VertexHandle > list;
    zeroBased3D->get_all_vertices( list, err );
    CPPUNIT_ASSERT( !err );
    CPPUNIT_ASSERT_EQUAL( (size_t)9, list.size() );
    CPPUNIT_ASSERT_EQUAL( (size_t)0, (size_t)list[0] );
    CPPUNIT_ASSERT_EQUAL( (size_t)1, (size_t)list[1] );
    CPPUNIT_ASSERT_EQUAL( (size_t)2, (size_t)list[2] );
    CPPUNIT_ASSERT_EQUAL( (size_t)3, (size_t)list[3] );
    CPPUNIT_ASSERT_EQUAL( (size_t)4, (size_t)list[4] );
    CPPUNIT_ASSERT_EQUAL( (size_t)5, (size_t)list[5] );
    CPPUNIT_ASSERT_EQUAL( (size_t)6, (size_t)list[6] );
    CPPUNIT_ASSERT_EQUAL( (size_t)7, (size_t)list[7] );
    CPPUNIT_ASSERT_EQUAL( (size_t)8, (size_t)list[8] );
}

void ArrayMeshTest::test_get_all_vertices_one_based()
{
    MsqPrintError err( std::cerr );
    std::vector< Mesh::VertexHandle > list;
    oneBased3D->get_all_vertices( list, err );
    CPPUNIT_ASSERT( !err );
    CPPUNIT_ASSERT_EQUAL( (size_t)9, list.size() );
    CPPUNIT_ASSERT_EQUAL( (size_t)1, (size_t)list[0] );
    CPPUNIT_ASSERT_EQUAL( (size_t)2, (size_t)list[1] );
    CPPUNIT_ASSERT_EQUAL( (size_t)3, (size_t)list[2] );
    CPPUNIT_ASSERT_EQUAL( (size_t)4, (size_t)list[3] );
    CPPUNIT_ASSERT_EQUAL( (size_t)5, (size_t)list[4] );
    CPPUNIT_ASSERT_EQUAL( (size_t)6, (size_t)list[5] );
    CPPUNIT_ASSERT_EQUAL( (size_t)7, (size_t)list[6] );
    CPPUNIT_ASSERT_EQUAL( (size_t)8, (size_t)list[7] );
    CPPUNIT_ASSERT_EQUAL( (size_t)9, (size_t)list[8] );
}

void ArrayMeshTest::test_vertex_iterator()
{
    MsqPrintError err( std::cerr );
    VertexIterator* iter = zeroBased3D->vertex_iterator( err );
    CPPUNIT_ASSERT( !err );
    std::unique_ptr< VertexIterator > deleter( iter );

    CPPUNIT_ASSERT( !iter->is_at_end() );
    CPPUNIT_ASSERT_EQUAL( (size_t)0, (size_t)iter->operator*() );
    iter->operator++();
    CPPUNIT_ASSERT( !iter->is_at_end() );
    CPPUNIT_ASSERT_EQUAL( (size_t)1, (size_t)iter->operator*() );
    iter->operator++();
    CPPUNIT_ASSERT( !iter->is_at_end() );
    CPPUNIT_ASSERT_EQUAL( (size_t)2, (size_t)iter->operator*() );
    iter->operator++();
    CPPUNIT_ASSERT( !iter->is_at_end() );
    CPPUNIT_ASSERT_EQUAL( (size_t)3, (size_t)iter->operator*() );
    iter->operator++();
    CPPUNIT_ASSERT( !iter->is_at_end() );
    CPPUNIT_ASSERT_EQUAL( (size_t)4, (size_t)iter->operator*() );
    iter->operator++();
    CPPUNIT_ASSERT( !iter->is_at_end() );
    CPPUNIT_ASSERT_EQUAL( (size_t)5, (size_t)iter->operator*() );
    iter->operator++();
    CPPUNIT_ASSERT( !iter->is_at_end() );
    CPPUNIT_ASSERT_EQUAL( (size_t)6, (size_t)iter->operator*() );
    iter->operator++();
    CPPUNIT_ASSERT( !iter->is_at_end() );
    CPPUNIT_ASSERT_EQUAL( (size_t)7, (size_t)iter->operator*() );
    iter->operator++();
    CPPUNIT_ASSERT( iter->is_at_end() );
    CPPUNIT_ASSERT_EQUAL( (size_t)8, (size_t)iter->operator*() );

    iter->restart();
    CPPUNIT_ASSERT_EQUAL( (size_t)0, (size_t)iter->operator*() );
}

void ArrayMeshTest::test_vertex_iterator_one_based()
{
    MsqPrintError err( std::cerr );
    VertexIterator* iter = oneBased3D->vertex_iterator( err );
    CPPUNIT_ASSERT( !err );
    std::unique_ptr< VertexIterator > deleter( iter );

    CPPUNIT_ASSERT( !iter->is_at_end() );
    CPPUNIT_ASSERT_EQUAL( (size_t)1, (size_t)iter->operator*() );
    iter->operator++();
    CPPUNIT_ASSERT( !iter->is_at_end() );
    CPPUNIT_ASSERT_EQUAL( (size_t)2, (size_t)iter->operator*() );
    iter->operator++();
    CPPUNIT_ASSERT( !iter->is_at_end() );
    CPPUNIT_ASSERT_EQUAL( (size_t)3, (size_t)iter->operator*() );
    iter->operator++();
    CPPUNIT_ASSERT( !iter->is_at_end() );
    CPPUNIT_ASSERT_EQUAL( (size_t)4, (size_t)iter->operator*() );
    iter->operator++();
    CPPUNIT_ASSERT( !iter->is_at_end() );
    CPPUNIT_ASSERT_EQUAL( (size_t)5, (size_t)iter->operator*() );
    iter->operator++();
    CPPUNIT_ASSERT( !iter->is_at_end() );
    CPPUNIT_ASSERT_EQUAL( (size_t)6, (size_t)iter->operator*() );
    iter->operator++();
    CPPUNIT_ASSERT( !iter->is_at_end() );
    CPPUNIT_ASSERT_EQUAL( (size_t)7, (size_t)iter->operator*() );
    iter->operator++();
    CPPUNIT_ASSERT( !iter->is_at_end() );
    CPPUNIT_ASSERT_EQUAL( (size_t)8, (size_t)iter->operator*() );
    iter->operator++();
    CPPUNIT_ASSERT( iter->is_at_end() );
    CPPUNIT_ASSERT_EQUAL( (size_t)9, (size_t)iter->operator*() );

    iter->restart();
    CPPUNIT_ASSERT_EQUAL( (size_t)1, (size_t)iter->operator*() );
}

void ArrayMeshTest::test_element_iterator()
{
    MsqPrintError err( std::cerr );
    ElementIterator* iter = zeroBased3D->element_iterator( err );
    CPPUNIT_ASSERT( !err );
    std::unique_ptr< ElementIterator > deleter( iter );

    CPPUNIT_ASSERT( !iter->is_at_end() );
    CPPUNIT_ASSERT_EQUAL( (size_t)0, (size_t)iter->operator*() );
    iter->operator++();
    CPPUNIT_ASSERT( !iter->is_at_end() );
    CPPUNIT_ASSERT_EQUAL( (size_t)1, (size_t)iter->operator*() );
    iter->operator++();
    CPPUNIT_ASSERT( !iter->is_at_end() );
    CPPUNIT_ASSERT_EQUAL( (size_t)2, (size_t)iter->operator*() );
    iter->operator++();
    CPPUNIT_ASSERT( iter->is_at_end() );
    CPPUNIT_ASSERT_EQUAL( (size_t)3, (size_t)iter->operator*() );

    iter->restart();
    CPPUNIT_ASSERT_EQUAL( (size_t)0, (size_t)iter->operator*() );
}

void ArrayMeshTest::test_vertices_get_fixed_flag()
{
    MsqPrintError err( std::cerr );
    const size_t verts[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 4 };
    std::vector< bool > flags;
    zeroBased3D->vertices_get_fixed_flag( (const Mesh::VertexHandle*)verts, flags, 10, err );
    CPPUNIT_ASSERT( !err );
    CPPUNIT_ASSERT_EQUAL( (size_t)10, flags.size() );
    CPPUNIT_ASSERT_EQUAL( true, (bool)flags[0] );
    CPPUNIT_ASSERT_EQUAL( true, (bool)flags[1] );
    CPPUNIT_ASSERT_EQUAL( true, (bool)flags[2] );
    CPPUNIT_ASSERT_EQUAL( true, (bool)flags[3] );
    CPPUNIT_ASSERT_EQUAL( false, (bool)flags[4] );
    CPPUNIT_ASSERT_EQUAL( true, (bool)flags[5] );
    CPPUNIT_ASSERT_EQUAL( true, (bool)flags[6] );
    CPPUNIT_ASSERT_EQUAL( true, (bool)flags[7] );
    CPPUNIT_ASSERT_EQUAL( true, (bool)flags[8] );
    CPPUNIT_ASSERT_EQUAL( false, (bool)flags[9] );
}

void ArrayMeshTest::test_vertices_get_coordinates()
{
    MsqPrintError err( std::cerr );
    const size_t verts[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 4 };
    MsqVertex coords[10];
    zeroBased3D->vertices_get_coordinates( (const Mesh::VertexHandle*)verts, coords, 10, err );
    CPPUNIT_ASSERT( !err );
    CPPUNIT_ASSERT_VECTORS_EQUAL( Vector3D( coords_3d + 0 ), coords[0], DBL_EPSILON );
    CPPUNIT_ASSERT_VECTORS_EQUAL( Vector3D( coords_3d + 3 ), coords[1], DBL_EPSILON );
    CPPUNIT_ASSERT_VECTORS_EQUAL( Vector3D( coords_3d + 6 ), coords[2], DBL_EPSILON );
    CPPUNIT_ASSERT_VECTORS_EQUAL( Vector3D( coords_3d + 9 ), coords[3], DBL_EPSILON );
    CPPUNIT_ASSERT_VECTORS_EQUAL( Vector3D( coords_3d + 12 ), coords[4], DBL_EPSILON );
    CPPUNIT_ASSERT_VECTORS_EQUAL( Vector3D( coords_3d + 15 ), coords[5], DBL_EPSILON );
    CPPUNIT_ASSERT_VECTORS_EQUAL( Vector3D( coords_3d + 18 ), coords[6], DBL_EPSILON );
    CPPUNIT_ASSERT_VECTORS_EQUAL( Vector3D( coords_3d + 21 ), coords[7], DBL_EPSILON );
    CPPUNIT_ASSERT_VECTORS_EQUAL( Vector3D( coords_3d + 24 ), coords[8], DBL_EPSILON );
    CPPUNIT_ASSERT_VECTORS_EQUAL( Vector3D( coords_3d + 12 ), coords[4], DBL_EPSILON );
}

void ArrayMeshTest::test_vertices_get_coordinates_two_d()
{
    MsqPrintError err( std::cerr );
    const size_t verts[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 4 };
    MsqVertex coords[10];
    zeroBased2D->vertices_get_coordinates( (const Mesh::VertexHandle*)verts, coords, 10, err );
    CPPUNIT_ASSERT( !err );
    CPPUNIT_ASSERT_VECTORS_EQUAL( Vector3D( coords_2d[0], coords_2d[1], 0 ), coords[0], DBL_EPSILON );
    CPPUNIT_ASSERT_VECTORS_EQUAL( Vector3D( coords_2d[2], coords_2d[3], 0 ), coords[1], DBL_EPSILON );
    CPPUNIT_ASSERT_VECTORS_EQUAL( Vector3D( coords_2d[4], coords_2d[5], 0 ), coords[2], DBL_EPSILON );
    CPPUNIT_ASSERT_VECTORS_EQUAL( Vector3D( coords_2d[6], coords_2d[7], 0 ), coords[3], DBL_EPSILON );
    CPPUNIT_ASSERT_VECTORS_EQUAL( Vector3D( coords_2d[8], coords_2d[9], 0 ), coords[4], DBL_EPSILON );
    CPPUNIT_ASSERT_VECTORS_EQUAL( Vector3D( coords_2d[10], coords_2d[11], 0 ), coords[5], DBL_EPSILON );
    CPPUNIT_ASSERT_VECTORS_EQUAL( Vector3D( coords_2d[12], coords_2d[13], 0 ), coords[6], DBL_EPSILON );
    CPPUNIT_ASSERT_VECTORS_EQUAL( Vector3D( coords_2d[14], coords_2d[15], 0 ), coords[7], DBL_EPSILON );
    CPPUNIT_ASSERT_VECTORS_EQUAL( Vector3D( coords_2d[16], coords_2d[17], 0 ), coords[8], DBL_EPSILON );
    CPPUNIT_ASSERT_VECTORS_EQUAL( Vector3D( coords_2d[8], coords_2d[9], 0 ), coords[9], DBL_EPSILON );
}

void ArrayMeshTest::test_vertices_get_coordinates_one_based()
{
    MsqPrintError err( std::cerr );
    const size_t verts[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 5 };
    MsqVertex coords[10];
    oneBased3D->vertices_get_coordinates( (const Mesh::VertexHandle*)verts, coords, 10, err );
    CPPUNIT_ASSERT( !err );
    CPPUNIT_ASSERT_VECTORS_EQUAL( Vector3D( coords_3d + 0 ), coords[0], DBL_EPSILON );
    CPPUNIT_ASSERT_VECTORS_EQUAL( Vector3D( coords_3d + 3 ), coords[1], DBL_EPSILON );
    CPPUNIT_ASSERT_VECTORS_EQUAL( Vector3D( coords_3d + 6 ), coords[2], DBL_EPSILON );
    CPPUNIT_ASSERT_VECTORS_EQUAL( Vector3D( coords_3d + 9 ), coords[3], DBL_EPSILON );
    CPPUNIT_ASSERT_VECTORS_EQUAL( Vector3D( coords_3d + 12 ), coords[4], DBL_EPSILON );
    CPPUNIT_ASSERT_VECTORS_EQUAL( Vector3D( coords_3d + 15 ), coords[5], DBL_EPSILON );
    CPPUNIT_ASSERT_VECTORS_EQUAL( Vector3D( coords_3d + 18 ), coords[6], DBL_EPSILON );
    CPPUNIT_ASSERT_VECTORS_EQUAL( Vector3D( coords_3d + 21 ), coords[7], DBL_EPSILON );
    CPPUNIT_ASSERT_VECTORS_EQUAL( Vector3D( coords_3d + 24 ), coords[8], DBL_EPSILON );
    CPPUNIT_ASSERT_VECTORS_EQUAL( Vector3D( coords_3d + 12 ), coords[4], DBL_EPSILON );
}

void ArrayMeshTest::test_vertex_set_coordinates()
{
    MsqPrintError err( std::cerr );
    Mesh::VertexHandle vert = (Mesh::VertexHandle)4;
    Vector3D new_pos( 5, 5, 5 );
    MsqVertex pos;
    zeroBased3D->vertex_set_coordinates( vert, new_pos, err );
    CPPUNIT_ASSERT( !err );
    zeroBased3D->vertices_get_coordinates( &vert, &pos, 1, err );
    CPPUNIT_ASSERT( !err );
    CPPUNIT_ASSERT_VECTORS_EQUAL( new_pos, pos, DBL_EPSILON );
}

void ArrayMeshTest::test_vertex_set_coordinates_two_d()
{
    MsqPrintError err( std::cerr );
    Mesh::VertexHandle vert = (Mesh::VertexHandle)4;
    Vector3D new_pos( 5, 5, 5 );
    MsqVertex pos;
    zeroBased2D->vertex_set_coordinates( vert, new_pos, err );
    CPPUNIT_ASSERT( !err );
    zeroBased2D->vertices_get_coordinates( &vert, &pos, 1, err );
    CPPUNIT_ASSERT( !err );
    new_pos[2] = 0;
    CPPUNIT_ASSERT_VECTORS_EQUAL( new_pos, pos, DBL_EPSILON );
}

void ArrayMeshTest::test_vertex_set_coordinates_one_based()
{
    MsqPrintError err( std::cerr );
    Mesh::VertexHandle vert = (Mesh::VertexHandle)5;
    Vector3D new_pos( 5, 5, 5 );
    MsqVertex pos;
    oneBased3D->vertex_set_coordinates( vert, new_pos, err );
    CPPUNIT_ASSERT( !err );
    oneBased3D->vertices_get_coordinates( &vert, &pos, 1, err );
    CPPUNIT_ASSERT( !err );
    CPPUNIT_ASSERT_VECTORS_EQUAL( new_pos, pos, DBL_EPSILON );
}

void ArrayMeshTest::test_vertex_set_byte()
{
    MsqPrintError err( std::cerr );
    unsigned char byte      = 'A';
    Mesh::VertexHandle vert = (Mesh::VertexHandle)5;
    zeroBased3D->vertex_set_byte( vert, byte, err );
    CPPUNIT_ASSERT( !err );
    byte = '0';
    zeroBased3D->vertex_get_byte( vert, &byte, err );
    CPPUNIT_ASSERT( !err );
    CPPUNIT_ASSERT_EQUAL( (unsigned char)'A', byte );
}

void ArrayMeshTest::test_vertices_set_byte()
{
    MsqPrintError err( std::cerr );
    const size_t verts[]        = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 4 };
    const unsigned char bytes[] = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'E' };
    unsigned char b[10];
    memset( b, 0, 10 );
    zeroBased3D->vertices_set_byte( (const Mesh::VertexHandle*)verts, bytes, 10, err );
    CPPUNIT_ASSERT( !err );
    zeroBased3D->vertices_get_byte( (const Mesh::VertexHandle*)verts, b, 10, err );
    CPPUNIT_ASSERT( !err );
    CPPUNIT_ASSERT_EQUAL( bytes[0], b[0] );
    CPPUNIT_ASSERT_EQUAL( bytes[1], b[1] );
    CPPUNIT_ASSERT_EQUAL( bytes[2], b[2] );
    CPPUNIT_ASSERT_EQUAL( bytes[3], b[3] );
    CPPUNIT_ASSERT_EQUAL( bytes[4], b[4] );
    CPPUNIT_ASSERT_EQUAL( bytes[5], b[5] );
    CPPUNIT_ASSERT_EQUAL( bytes[6], b[6] );
    CPPUNIT_ASSERT_EQUAL( bytes[7], b[7] );
    CPPUNIT_ASSERT_EQUAL( bytes[8], b[8] );
}

void ArrayMeshTest::test_vertices_get_attached_elements()
{
    MsqPrintError err( std::cerr );
    const size_t verts[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8 };
    std::vector< Mesh::ElementHandle > elems;
    std::vector< size_t > offsets;
    zeroBased3D->vertices_get_attached_elements( (const Mesh::VertexHandle*)verts, 9, elems, offsets, err );
    CPPUNIT_ASSERT( !err );

    CPPUNIT_ASSERT_EQUAL( (size_t)16, elems.size() );
    CPPUNIT_ASSERT( offsets.size() == 9 || offsets.size() == 10 );
    if( offsets.size() == 10 ) CPPUNIT_ASSERT_EQUAL( size_t( 16 ), offsets[9] );

    // vert 0
    CPPUNIT_ASSERT_EQUAL( (size_t)0, offsets[0] );
    CPPUNIT_ASSERT_EQUAL( (size_t)0, (size_t)elems[0] );
    // vert 1
    CPPUNIT_ASSERT_EQUAL( (size_t)1, offsets[1] );
    CPPUNIT_ASSERT_EQUAL( (size_t)0, (size_t)elems[1] );
    CPPUNIT_ASSERT_EQUAL( (size_t)1, (size_t)elems[2] );
    // vert 2
    CPPUNIT_ASSERT_EQUAL( (size_t)3, offsets[2] );
    CPPUNIT_ASSERT_EQUAL( (size_t)1, (size_t)elems[3] );
    // vert 3
    CPPUNIT_ASSERT_EQUAL( (size_t)4, offsets[3] );
    CPPUNIT_ASSERT_EQUAL( (size_t)0, (size_t)elems[4] );
    CPPUNIT_ASSERT_EQUAL( (size_t)2, (size_t)elems[5] );
    // vert 4
    CPPUNIT_ASSERT_EQUAL( (size_t)6, offsets[4] );
    CPPUNIT_ASSERT_EQUAL( (size_t)0, (size_t)elems[6] );
    CPPUNIT_ASSERT_EQUAL( (size_t)1, (size_t)elems[7] );
    CPPUNIT_ASSERT_EQUAL( (size_t)2, (size_t)elems[8] );
    CPPUNIT_ASSERT_EQUAL( (size_t)3, (size_t)elems[9] );
    // vert 5
    CPPUNIT_ASSERT_EQUAL( (size_t)10, offsets[5] );
    CPPUNIT_ASSERT_EQUAL( (size_t)1, (size_t)elems[10] );
    CPPUNIT_ASSERT_EQUAL( (size_t)3, (size_t)elems[11] );
    // vert 6
    CPPUNIT_ASSERT_EQUAL( (size_t)12, offsets[6] );
    CPPUNIT_ASSERT_EQUAL( (size_t)2, (size_t)elems[12] );
    // vert 7
    CPPUNIT_ASSERT_EQUAL( (size_t)13, offsets[7] );
    CPPUNIT_ASSERT_EQUAL( (size_t)2, (size_t)elems[13] );
    CPPUNIT_ASSERT_EQUAL( (size_t)3, (size_t)elems[14] );
    // vert 8
    CPPUNIT_ASSERT_EQUAL( (size_t)15, offsets[8] );
    CPPUNIT_ASSERT_EQUAL( (size_t)3, (size_t)elems[15] );
}

void ArrayMeshTest::test_vertices_get_attached_elements_one_based()
{
    MsqPrintError err( std::cerr );
    const size_t verts[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
    std::vector< Mesh::ElementHandle > elems;
    std::vector< size_t > offsets;
    oneBased3D->vertices_get_attached_elements( (const Mesh::VertexHandle*)verts, 9, elems, offsets, err );
    CPPUNIT_ASSERT( !err );

    CPPUNIT_ASSERT_EQUAL( (size_t)16, elems.size() );
    CPPUNIT_ASSERT( offsets.size() == 9 || offsets.size() == 10 );
    if( offsets.size() == 10 ) CPPUNIT_ASSERT_EQUAL( size_t( 16 ), offsets[9] );

    // vert 0
    CPPUNIT_ASSERT_EQUAL( (size_t)0, offsets[0] );
    CPPUNIT_ASSERT_EQUAL( (size_t)0, (size_t)elems[0] );
    // vert 1
    CPPUNIT_ASSERT_EQUAL( (size_t)1, offsets[1] );
    CPPUNIT_ASSERT_EQUAL( (size_t)0, (size_t)elems[1] );
    CPPUNIT_ASSERT_EQUAL( (size_t)1, (size_t)elems[2] );
    // vert 2
    CPPUNIT_ASSERT_EQUAL( (size_t)3, offsets[2] );
    CPPUNIT_ASSERT_EQUAL( (size_t)1, (size_t)elems[3] );
    // vert 3
    CPPUNIT_ASSERT_EQUAL( (size_t)4, offsets[3] );
    CPPUNIT_ASSERT_EQUAL( (size_t)0, (size_t)elems[4] );
    CPPUNIT_ASSERT_EQUAL( (size_t)2, (size_t)elems[5] );
    // vert 4
    CPPUNIT_ASSERT_EQUAL( (size_t)6, offsets[4] );
    CPPUNIT_ASSERT_EQUAL( (size_t)0, (size_t)elems[6] );
    CPPUNIT_ASSERT_EQUAL( (size_t)1, (size_t)elems[7] );
    CPPUNIT_ASSERT_EQUAL( (size_t)2, (size_t)elems[8] );
    CPPUNIT_ASSERT_EQUAL( (size_t)3, (size_t)elems[9] );
    // vert 5
    CPPUNIT_ASSERT_EQUAL( (size_t)10, offsets[5] );
    CPPUNIT_ASSERT_EQUAL( (size_t)1, (size_t)elems[10] );
    CPPUNIT_ASSERT_EQUAL( (size_t)3, (size_t)elems[11] );
    // vert 6
    CPPUNIT_ASSERT_EQUAL( (size_t)12, offsets[6] );
    CPPUNIT_ASSERT_EQUAL( (size_t)2, (size_t)elems[12] );
    // vert 7
    CPPUNIT_ASSERT_EQUAL( (size_t)13, offsets[7] );
    CPPUNIT_ASSERT_EQUAL( (size_t)2, (size_t)elems[13] );
    CPPUNIT_ASSERT_EQUAL( (size_t)3, (size_t)elems[14] );
    // vert 8
    CPPUNIT_ASSERT_EQUAL( (size_t)15, offsets[8] );
    CPPUNIT_ASSERT_EQUAL( (size_t)3, (size_t)elems[15] );
}

void ArrayMeshTest::test_elements_get_attached_vertices()
{
    MsqPrintError err( std::cerr );
    const size_t elems[] = { 3, 2, 1, 0 };
    std::vector< Mesh::VertexHandle > verts;
    std::vector< size_t > offsets;
    zeroBased3D->elements_get_attached_vertices( (const Mesh::ElementHandle*)elems, 4, verts, offsets, err );
    CPPUNIT_ASSERT( !err );
    CPPUNIT_ASSERT_EQUAL( (size_t)16, verts.size() );
    CPPUNIT_ASSERT( offsets.size() == 4 || offsets.size() == 5 );
    if( offsets.size() == 5 ) CPPUNIT_ASSERT_EQUAL( (size_t)16, offsets[4] );

    // elem 3
    CPPUNIT_ASSERT_EQUAL( (size_t)0, offsets[0] );
    CPPUNIT_ASSERT_EQUAL( (size_t)7, (size_t)verts[0] );
    CPPUNIT_ASSERT_EQUAL( (size_t)8, (size_t)verts[1] );
    CPPUNIT_ASSERT_EQUAL( (size_t)5, (size_t)verts[2] );
    CPPUNIT_ASSERT_EQUAL( (size_t)4, (size_t)verts[3] );

    // elem 2
    CPPUNIT_ASSERT_EQUAL( (size_t)4, offsets[1] );
    CPPUNIT_ASSERT_EQUAL( (size_t)6, (size_t)verts[4] );
    CPPUNIT_ASSERT_EQUAL( (size_t)7, (size_t)verts[5] );
    CPPUNIT_ASSERT_EQUAL( (size_t)4, (size_t)verts[6] );
    CPPUNIT_ASSERT_EQUAL( (size_t)3, (size_t)verts[7] );

    // elem 1
    CPPUNIT_ASSERT_EQUAL( (size_t)8, offsets[2] );
    CPPUNIT_ASSERT_EQUAL( (size_t)4, (size_t)verts[8] );
    CPPUNIT_ASSERT_EQUAL( (size_t)5, (size_t)verts[9] );
    CPPUNIT_ASSERT_EQUAL( (size_t)2, (size_t)verts[10] );
    CPPUNIT_ASSERT_EQUAL( (size_t)1, (size_t)verts[11] );

    // elem 0
    CPPUNIT_ASSERT_EQUAL( (size_t)12, offsets[3] );
    CPPUNIT_ASSERT_EQUAL( (size_t)3, (size_t)verts[12] );
    CPPUNIT_ASSERT_EQUAL( (size_t)4, (size_t)verts[13] );
    CPPUNIT_ASSERT_EQUAL( (size_t)1, (size_t)verts[14] );
    CPPUNIT_ASSERT_EQUAL( (size_t)0, (size_t)verts[15] );
}

void ArrayMeshTest::test_elements_get_topologies()
{
    MsqPrintError err( std::cerr );
    const size_t elems[]  = { 3, 2, 1, 0, 1, 2, 3, 0 };
    const size_t num_elem = sizeof( elems ) / sizeof( elems[0] );
    EntityTopology topo[num_elem];
    memset( topo, 0, sizeof( topo ) );
    zeroBased3D->elements_get_topologies( (const Mesh::ElementHandle*)elems, topo, num_elem, err );
    CPPUNIT_ASSERT( !err );
    for( size_t i = 0; i < num_elem; ++i )
        CPPUNIT_ASSERT_EQUAL( (int)QUADRILATERAL, (int)topo[i] );
}

void ArrayMeshTest::test_vertices_get_attached_elements_mixed()
{
    MsqPrintError err( std::cerr );
    const size_t verts[] = { 0, 1, 2, 3, 4, 5, 6, 7 };
    std::vector< Mesh::ElementHandle > elems;
    std::vector< size_t > offsets;
    mixedZeroBased->vertices_get_attached_elements( (const Mesh::VertexHandle*)verts, 8, elems, offsets, err );
    CPPUNIT_ASSERT( !err );

    CPPUNIT_ASSERT_EQUAL( (size_t)14, elems.size() );
    CPPUNIT_ASSERT( offsets.size() == 8 || offsets.size() == 9 );
    if( offsets.size() == 9 ) CPPUNIT_ASSERT_EQUAL( elems.size(), offsets[8] );

    // vert 0
    CPPUNIT_ASSERT_EQUAL( (size_t)0, offsets[0] );
    CPPUNIT_ASSERT_EQUAL( (size_t)0, (size_t)elems[0] );
    // vert 1
    CPPUNIT_ASSERT_EQUAL( (size_t)1, offsets[1] );
    CPPUNIT_ASSERT_EQUAL( (size_t)0, (size_t)elems[1] );
    CPPUNIT_ASSERT_EQUAL( (size_t)1, (size_t)elems[2] );
    CPPUNIT_ASSERT_EQUAL( (size_t)2, (size_t)elems[3] );
    // vert 2
    CPPUNIT_ASSERT_EQUAL( (size_t)4, offsets[2] );
    CPPUNIT_ASSERT_EQUAL( (size_t)2, (size_t)elems[4] );
    CPPUNIT_ASSERT_EQUAL( (size_t)3, (size_t)elems[5] );
    // vert 3
    CPPUNIT_ASSERT_EQUAL( (size_t)6, offsets[3] );
    CPPUNIT_ASSERT_EQUAL( (size_t)3, (size_t)elems[6] );
    // vert 4
    CPPUNIT_ASSERT_EQUAL( (size_t)7, offsets[4] );
    CPPUNIT_ASSERT_EQUAL( (size_t)3, (size_t)elems[7] );
    // vert 5
    CPPUNIT_ASSERT_EQUAL( (size_t)8, offsets[5] );
    CPPUNIT_ASSERT_EQUAL( (size_t)1, (size_t)elems[8] );
    CPPUNIT_ASSERT_EQUAL( (size_t)2, (size_t)elems[9] );
    CPPUNIT_ASSERT_EQUAL( (size_t)3, (size_t)elems[10] );
    // vert 6
    CPPUNIT_ASSERT_EQUAL( (size_t)11, offsets[6] );
    CPPUNIT_ASSERT_EQUAL( (size_t)0, (size_t)elems[11] );
    CPPUNIT_ASSERT_EQUAL( (size_t)1, (size_t)elems[12] );
    // vert 7
    CPPUNIT_ASSERT_EQUAL( (size_t)13, offsets[7] );
    CPPUNIT_ASSERT_EQUAL( (size_t)0, (size_t)elems[13] );
}

void ArrayMeshTest::test_vertices_get_attached_elements_mixed_one_based()
{
    MsqPrintError err( std::cerr );
    const size_t verts[] = { 1, 2, 3, 4, 5, 6, 7, 8 };
    std::vector< Mesh::ElementHandle > elems;
    std::vector< size_t > offsets;
    mixedOneBased->vertices_get_attached_elements( (const Mesh::VertexHandle*)verts, 8, elems, offsets, err );
    CPPUNIT_ASSERT( !err );

    CPPUNIT_ASSERT_EQUAL( (size_t)14, elems.size() );
    CPPUNIT_ASSERT( offsets.size() == 8 || offsets.size() == 9 );
    if( offsets.size() == 9 ) CPPUNIT_ASSERT_EQUAL( elems.size(), offsets[8] );

    // vert 0
    CPPUNIT_ASSERT_EQUAL( (size_t)0, offsets[0] );
    CPPUNIT_ASSERT_EQUAL( (size_t)0, (size_t)elems[0] );
    // vert 1
    CPPUNIT_ASSERT_EQUAL( (size_t)1, offsets[1] );
    CPPUNIT_ASSERT_EQUAL( (size_t)0, (size_t)elems[1] );
    CPPUNIT_ASSERT_EQUAL( (size_t)1, (size_t)elems[2] );
    CPPUNIT_ASSERT_EQUAL( (size_t)2, (size_t)elems[3] );
    // vert 2
    CPPUNIT_ASSERT_EQUAL( (size_t)4, offsets[2] );
    CPPUNIT_ASSERT_EQUAL( (size_t)2, (size_t)elems[4] );
    CPPUNIT_ASSERT_EQUAL( (size_t)3, (size_t)elems[5] );
    // vert 3
    CPPUNIT_ASSERT_EQUAL( (size_t)6, offsets[3] );
    CPPUNIT_ASSERT_EQUAL( (size_t)3, (size_t)elems[6] );
    // vert 4
    CPPUNIT_ASSERT_EQUAL( (size_t)7, offsets[4] );
    CPPUNIT_ASSERT_EQUAL( (size_t)3, (size_t)elems[7] );
    // vert 5
    CPPUNIT_ASSERT_EQUAL( (size_t)8, offsets[5] );
    CPPUNIT_ASSERT_EQUAL( (size_t)1, (size_t)elems[8] );
    CPPUNIT_ASSERT_EQUAL( (size_t)2, (size_t)elems[9] );
    CPPUNIT_ASSERT_EQUAL( (size_t)3, (size_t)elems[10] );
    // vert 6
    CPPUNIT_ASSERT_EQUAL( (size_t)11, offsets[6] );
    CPPUNIT_ASSERT_EQUAL( (size_t)0, (size_t)elems[11] );
    CPPUNIT_ASSERT_EQUAL( (size_t)1, (size_t)elems[12] );
    // vert 7
    CPPUNIT_ASSERT_EQUAL( (size_t)13, offsets[7] );
    CPPUNIT_ASSERT_EQUAL( (size_t)0, (size_t)elems[13] );
}

void ArrayMeshTest::test_elements_get_attached_vertices_mixed()
{
    MsqPrintError err( std::cerr );
    const size_t elems[] = { 3, 2, 1, 0 };
    std::vector< Mesh::VertexHandle > verts;
    std::vector< size_t > offsets;
    mixedZeroBased->elements_get_attached_vertices( (const Mesh::ElementHandle*)elems, 4, verts, offsets, err );
    CPPUNIT_ASSERT( !err );
    CPPUNIT_ASSERT_EQUAL( (size_t)14, verts.size() );
    CPPUNIT_ASSERT( offsets.size() == 4 || offsets.size() == 5 );
    if( offsets.size() == 5 ) CPPUNIT_ASSERT_EQUAL( verts.size(), offsets[4] );

    // elem 3
    CPPUNIT_ASSERT_EQUAL( (size_t)0, offsets[0] );
    CPPUNIT_ASSERT_EQUAL( (size_t)5, (size_t)verts[0] );
    CPPUNIT_ASSERT_EQUAL( (size_t)4, (size_t)verts[1] );
    CPPUNIT_ASSERT_EQUAL( (size_t)3, (size_t)verts[2] );
    CPPUNIT_ASSERT_EQUAL( (size_t)2, (size_t)verts[3] );

    // elem 2
    CPPUNIT_ASSERT_EQUAL( (size_t)4, offsets[1] );
    CPPUNIT_ASSERT_EQUAL( (size_t)2, (size_t)verts[4] );
    CPPUNIT_ASSERT_EQUAL( (size_t)1, (size_t)verts[5] );
    CPPUNIT_ASSERT_EQUAL( (size_t)5, (size_t)verts[6] );

    // elem 1
    CPPUNIT_ASSERT_EQUAL( (size_t)7, offsets[2] );
    CPPUNIT_ASSERT_EQUAL( (size_t)6, (size_t)verts[7] );
    CPPUNIT_ASSERT_EQUAL( (size_t)5, (size_t)verts[8] );
    CPPUNIT_ASSERT_EQUAL( (size_t)1, (size_t)verts[9] );

    // elem 0
    CPPUNIT_ASSERT_EQUAL( (size_t)10, offsets[3] );
    CPPUNIT_ASSERT_EQUAL( (size_t)7, (size_t)verts[10] );
    CPPUNIT_ASSERT_EQUAL( (size_t)6, (size_t)verts[11] );
    CPPUNIT_ASSERT_EQUAL( (size_t)1, (size_t)verts[12] );
    CPPUNIT_ASSERT_EQUAL( (size_t)0, (size_t)verts[13] );
}

void ArrayMeshTest::test_elements_get_attached_vertices_mixed_one_based()
{
    MsqPrintError err( std::cerr );
    const size_t elems[] = { 3, 2, 1, 0 };
    std::vector< Mesh::VertexHandle > verts;
    std::vector< size_t > offsets;
    mixedOneBased->elements_get_attached_vertices( (const Mesh::ElementHandle*)elems, 4, verts, offsets, err );
    CPPUNIT_ASSERT( !err );
    CPPUNIT_ASSERT_EQUAL( (size_t)14, verts.size() );
    CPPUNIT_ASSERT( offsets.size() == 4 || offsets.size() == 5 );
    if( offsets.size() == 5 ) CPPUNIT_ASSERT_EQUAL( verts.size(), offsets[4] );

    // elem 3
    CPPUNIT_ASSERT_EQUAL( (size_t)0, offsets[0] );
    CPPUNIT_ASSERT_EQUAL( (size_t)6, (size_t)verts[0] );
    CPPUNIT_ASSERT_EQUAL( (size_t)5, (size_t)verts[1] );
    CPPUNIT_ASSERT_EQUAL( (size_t)4, (size_t)verts[2] );
    CPPUNIT_ASSERT_EQUAL( (size_t)3, (size_t)verts[3] );

    // elem 2
    CPPUNIT_ASSERT_EQUAL( (size_t)4, offsets[1] );
    CPPUNIT_ASSERT_EQUAL( (size_t)3, (size_t)verts[4] );
    CPPUNIT_ASSERT_EQUAL( (size_t)2, (size_t)verts[5] );
    CPPUNIT_ASSERT_EQUAL( (size_t)6, (size_t)verts[6] );

    // elem 1
    CPPUNIT_ASSERT_EQUAL( (size_t)7, offsets[2] );
    CPPUNIT_ASSERT_EQUAL( (size_t)7, (size_t)verts[7] );
    CPPUNIT_ASSERT_EQUAL( (size_t)6, (size_t)verts[8] );
    CPPUNIT_ASSERT_EQUAL( (size_t)2, (size_t)verts[9] );

    // elem 0
    CPPUNIT_ASSERT_EQUAL( (size_t)10, offsets[3] );
    CPPUNIT_ASSERT_EQUAL( (size_t)8, (size_t)verts[10] );
    CPPUNIT_ASSERT_EQUAL( (size_t)7, (size_t)verts[11] );
    CPPUNIT_ASSERT_EQUAL( (size_t)2, (size_t)verts[12] );
    CPPUNIT_ASSERT_EQUAL( (size_t)1, (size_t)verts[13] );
}

void ArrayMeshTest::test_elements_get_topologies_mixed()
{
    MsqPrintError err( std::cerr );
    const size_t elems[]  = { 3, 2, 1, 0, 1, 2, 3 };
    const size_t num_elem = sizeof( elems ) / sizeof( elems[0] );
    EntityTopology topo[num_elem];
    memset( topo, 0, sizeof( topo ) );
    mixedZeroBased->elements_get_topologies( (const Mesh::ElementHandle*)elems, topo, num_elem, err );
    CPPUNIT_ASSERT( !err );
    for( size_t i = 0; i < num_elem; ++i )
        CPPUNIT_ASSERT_EQUAL( (int)mixed_types[elems[i]], (int)topo[i] );
}

void ArrayMeshTest::test_tag_data( TagEntType type, TagStorage storage )
{
    // Select what we're working with given 'type' parameter
    ArrayMesh* const mesh = ( type == ONE_BASED_VERTEX ) ? oneBased3D : zeroBased3D;
    std::vector< Mesh::EntityHandle > entities;
    MsqError err;
    if( type == ELEMENT )
        mesh->get_all_elements( entities, err );
    else
        mesh->get_all_vertices( entities, err );
    ASSERT_NO_ERROR( err );

    // Create a tag
    char name1[] = "  _double_3";
    name1[0]     = 'A' + type;
    name1[1]     = 'A' + storage;
    TagHandle tag;
    std::vector< double > values( 3 * entities.size() );
    double dval = -5;
    for( std::vector< double >::iterator i = values.begin(); i != values.end(); ++i )
        *i = dval--;
    double* ele_ptr = ( type == ELEMENT ) ? arrptr( values ) : 0;
    double* vtx_ptr = ( type != ELEMENT ) ? arrptr( values ) : 0;
    if( storage == READONLY )
    {
        tag = mesh->add_read_only_tag_data( name1, Mesh::DOUBLE, 3, vtx_ptr, ele_ptr, 0, err );
        ASSERT_NO_ERROR( err );
    }
    else if( storage == WRITABLE )
    {
        tag = mesh->add_writable_tag_data( name1, Mesh::DOUBLE, 3, vtx_ptr, ele_ptr, 0, err );
        ASSERT_NO_ERROR( err );
    }
    else
    {
        assert( OWNED == storage );
        tag = mesh->tag_create( name1, Mesh::DOUBLE, 3, 0, err );
        ASSERT_NO_ERROR( err );
        if( type == ELEMENT )
            mesh->tag_set_element_data( tag, entities.size(), arrptr( entities ), arrptr( values ), err );
        else
            mesh->tag_set_vertex_data( tag, entities.size(), arrptr( entities ), arrptr( values ), err );
        ASSERT_NO_ERROR( err );
    }

    // Check tag properties
    TagHandle tag2 = mesh->tag_get( name1, err );
    ASSERT_NO_ERROR( err );
    CPPUNIT_ASSERT_EQUAL( tag, tag2 );
    std::string n;
    Mesh::TagType t;
    unsigned s;
    mesh->tag_properties( tag, n, t, s, err );
    ASSERT_NO_ERROR( err );
    CPPUNIT_ASSERT_EQUAL( std::string( name1 ), n );
    CPPUNIT_ASSERT_EQUAL( Mesh::DOUBLE, t );
    CPPUNIT_ASSERT_EQUAL( 3u, s );

    // Check values returned from tag_get_*_data
    std::vector< double > values2( 3 * entities.size() );
    if( ELEMENT == type )
        mesh->tag_get_element_data( tag, entities.size(), arrptr( entities ), arrptr( values2 ), err );
    else
        mesh->tag_get_vertex_data( tag, entities.size(), arrptr( entities ), arrptr( values2 ), err );
    ASSERT_NO_ERROR( err );
    ASSERT_STD_VECTORS_EQUAL( values, values2 );

    // check that we get an error for other type, because no default
    if( ELEMENT != type )
        mesh->tag_get_element_data( tag, entities.size(), arrptr( entities ), arrptr( values2 ), err );
    else
        mesh->tag_get_vertex_data( tag, entities.size(), arrptr( entities ), arrptr( values2 ), err );
    CPPUNIT_ASSERT_EQUAL( MsqError::TAG_NOT_FOUND, err.error_code() );
    err.clear();

    // check that we can or cannot modify the values as expected
    dval = entities.size() + 1;
    std::vector< double > values5( values.size() );
    for( std::vector< double >::iterator i = values5.begin(); i != values5.end(); ++i )
        *i = dval++;
    if( ELEMENT == type )
        mesh->tag_set_element_data( tag, entities.size(), arrptr( entities ), arrptr( values5 ), err );
    else
        mesh->tag_set_vertex_data( tag, entities.size(), arrptr( entities ), arrptr( values5 ), err );
    if( READONLY == storage )
    {
        CPPUNIT_ASSERT( err );
        err.clear();
    }
    else
    {
        ASSERT_NO_ERROR( err );
    }

    // check that the values are as expected
    if( READONLY != storage )
    {
        if( ELEMENT == type )
            mesh->tag_get_element_data( tag, entities.size(), arrptr( entities ), arrptr( values2 ), err );
        else
            mesh->tag_get_vertex_data( tag, entities.size(), arrptr( entities ), arrptr( values2 ), err );
        ASSERT_NO_ERROR( err );
        ASSERT_STD_VECTORS_EQUAL( values5, values2 );

        // if WRITABLE storeage, original input array should have changed also
        if( WRITABLE == storage )
        {
            ASSERT_STD_VECTORS_EQUAL( values, values5 );
        }
    }

    // create a new tag with a default value
    char name2[]            = "  _int_2";
    name2[0]                = 'A' + type;
    name2[1]                = 'A' + storage;
    const int default_val[] = { 'J', 'K' };
    if( READONLY == storage )
        tag = mesh->add_read_only_tag_data( name2, Mesh::INT, 2, 0, 0, default_val, err );
    else if( WRITABLE == storage )
        tag = mesh->add_writable_tag_data( name2, Mesh::INT, 2, 0, 0, default_val, err );
    else  // OWNED == storage
        tag = mesh->tag_create( name2, Mesh::INT, 2, default_val, err );
    ASSERT_NO_ERROR( err );

    // Check tag properties
    tag2 = mesh->tag_get( name2, err );
    ASSERT_NO_ERROR( err );
    CPPUNIT_ASSERT_EQUAL( tag, tag2 );
    mesh->tag_properties( tag, n, t, s, err );
    ASSERT_NO_ERROR( err );
    CPPUNIT_ASSERT_EQUAL( std::string( name2 ), n );
    CPPUNIT_ASSERT_EQUAL( Mesh::INT, t );
    CPPUNIT_ASSERT_EQUAL( 2u, s );

    // should get default value for each entity
    std::vector< int > values3( 2 * entities.size() );
    if( ELEMENT == type )
        mesh->tag_get_element_data( tag, entities.size(), arrptr( entities ), arrptr( values3 ), err );
    else
        mesh->tag_get_vertex_data( tag, entities.size(), arrptr( entities ), arrptr( values3 ), err );
    ASSERT_NO_ERROR( err );

    // check that we got the default value for every entity
    for( size_t i = 0; i < entities.size(); ++i )
    {
        CPPUNIT_ASSERT_EQUAL( default_val[0], values3[2 * i] );
        CPPUNIT_ASSERT_EQUAL( default_val[1], values3[2 * i + 1] );
    }

    // check that we cannot modify the values
    for( size_t i = 0; i < values3.size(); ++i )
        values[i] = i;
    if( ELEMENT == type )
        mesh->tag_set_element_data( tag, entities.size(), arrptr( entities ), arrptr( values3 ), err );
    else
        mesh->tag_set_vertex_data( tag, entities.size(), arrptr( entities ), arrptr( values3 ), err );
    if( OWNED != storage )
    {
        CPPUNIT_ASSERT( err );
        err.clear();
    }
    else
    {
        ASSERT_NO_ERROR( err );
    }

    // check that we did set the values as expected
    if( OWNED != storage )
    {
        std::vector< int > values4( values3.size() );
        if( ELEMENT == type )
            mesh->tag_get_element_data( tag, entities.size(), arrptr( entities ), arrptr( values4 ), err );
        else
            mesh->tag_get_vertex_data( tag, entities.size(), arrptr( entities ), arrptr( values4 ), err );
        ASSERT_NO_ERROR( err );
        ASSERT_STD_VECTORS_EQUAL( values3, values4 );
    }
}

void ArrayMeshTest::test_delete_tag()
{
    MsqError err;
    ArrayMesh* mesh = zeroBased2D;
    TagHandle tag, tag1, tag2, tag3;
    tag1 = mesh->add_read_only_tag_data( "name1", Mesh::BOOL, 1, 0, 0, 0, err );
    ASSERT_NO_ERROR( err );
    tag2 = mesh->add_writable_tag_data( "name2", Mesh::BYTE, 5, 0, 0, 0, err );
    ASSERT_NO_ERROR( err );
    tag3 = mesh->tag_create( "name3", Mesh::HANDLE, 2, 0, err );
    ASSERT_NO_ERROR( err );

    tag = mesh->tag_get( "name2", err );
    ASSERT_NO_ERROR( err );
    CPPUNIT_ASSERT_EQUAL( tag2, tag );

    mesh->tag_delete( tag2, err );
    ASSERT_NO_ERROR( err );
    tag = mesh->tag_get( "name2", err );<--- tag is assigned
    CPPUNIT_ASSERT_EQUAL( MsqError::TAG_NOT_FOUND, err.error_code() );
    err.clear();
    tag = mesh->tag_get( "name1", err );<--- tag is overwritten
    ASSERT_NO_ERROR( err );
    CPPUNIT_ASSERT_EQUAL( tag1, tag );
    tag = mesh->tag_get( "name3", err );
    ASSERT_NO_ERROR( err );
    CPPUNIT_ASSERT_EQUAL( tag3, tag );

    mesh->tag_delete( tag1, err );
    ASSERT_NO_ERROR( err );
    tag = mesh->tag_get( "name2", err );<--- tag is assigned
    CPPUNIT_ASSERT_EQUAL( MsqError::TAG_NOT_FOUND, err.error_code() );
    err.clear();
    tag = mesh->tag_get( "name1", err );<--- tag is overwritten<--- tag is assigned
    CPPUNIT_ASSERT_EQUAL( MsqError::TAG_NOT_FOUND, err.error_code() );
    err.clear();
    tag = mesh->tag_get( "name3", err );<--- tag is overwritten
    ASSERT_NO_ERROR( err );
    CPPUNIT_ASSERT_EQUAL( tag3, tag );

    mesh->tag_delete( tag3, err );
    ASSERT_NO_ERROR( err );
    tag = mesh->tag_get( "name2", err );<--- tag is assigned
    CPPUNIT_ASSERT_EQUAL( MsqError::TAG_NOT_FOUND, err.error_code() );
    err.clear();
    tag = mesh->tag_get( "name1", err );<--- tag is overwritten<--- tag is assigned
    CPPUNIT_ASSERT_EQUAL( MsqError::TAG_NOT_FOUND, err.error_code() );
    err.clear();
    tag = mesh->tag_get( "name3", err );<--- tag is overwritten
    CPPUNIT_ASSERT_EQUAL( MsqError::TAG_NOT_FOUND, err.error_code() );
    err.clear();
}