Ejemplo n.º 1
0
void BaseTestReadOnly::testRead() {
    File file = File::open("test_read_only.h5", FileMode::ReadOnly);

    Section section = file.getSection(section_id);
    Block block = file.getBlock(block_id);
    DataArray data_array = block.getDataArray(data_array_id);
    Dimension dim = data_array.getDimension(dim_index);
    SampledDimension dim_sampled = data_array.getDimension(dim_sampled_index).asSampledDimension();
    RangeDimension dim_range = data_array.getDimension(dim_range_index).asRangeDimension();
    SetDimension dim_set = data_array.getDimension(dim_set_index).asSetDimension();
    Tag tag = block.getTag(tag_id);
    MultiTag mtag = block.getMultiTag(mtag_id);
    Feature feature = tag.getFeature(feature_id);
    Property property = section.getProperty(property_id);

    // TODO use assertions here
    s << block.id() << block.name();
    s << data_array.id() << data_array.name();
    s << tag.id() << tag.name();
    s << mtag.id() << mtag.name();
    s << feature.id();
    s << property.id() << property.name();
    s << dim.index();
    s << dim_sampled.index();
    s << dim_range.index();
    s << dim_set.index();
    
    file.close();
}
Ejemplo n.º 2
0
void TestBlock::testMultiTagAccess() {
    vector<string> names = { "tag_a", "tag_b", "tag_c", "tag_d", "tag_e" };
    // create a valid positions data array below
    typedef boost::multi_array<double, 3>::index index;
    DataArray positions = block.createDataArray("array_one",
                                                "testdata",
                                                DataType::Double,
                                                nix::NDSize({ 3, 4, 2 }));
    boost::multi_array<double, 3> A(boost::extents[3][4][2]);
    int values = 0;
    for(index i = 0; i != 3; ++i)
        for(index j = 0; j != 4; ++j)
            for(index k = 0; k != 2; ++k)
                A[i][j][k] = values++;

    positions.setData(A);

    CPPUNIT_ASSERT(block.multiTagCount() == 0);
    CPPUNIT_ASSERT(block.multiTags().size() == 0);
    CPPUNIT_ASSERT(block.getMultiTag("invalid_id") == false);

    vector<string> ids;
    for (auto it = names.begin(); it != names.end(); it++) {
        MultiTag tag = block.createMultiTag(*it, "segment", positions);
        CPPUNIT_ASSERT(tag.name() == *it);

        ids.push_back(tag.id());
    }
    CPPUNIT_ASSERT_THROW(block.createMultiTag(names[0], "segment", positions),
                         DuplicateName);

    CPPUNIT_ASSERT(block.multiTagCount() == names.size());
    CPPUNIT_ASSERT(block.multiTags().size() == names.size());

    for (auto it = ids.begin(); it != ids.end(); it++) {
        MultiTag tag = block.getMultiTag(*it);
        CPPUNIT_ASSERT(block.hasMultiTag(*it) == true);
        CPPUNIT_ASSERT(tag.id() == *it);

        block.deleteMultiTag(*it);
    }

    CPPUNIT_ASSERT(block.multiTagCount() == 0);
    CPPUNIT_ASSERT(block.multiTags().size() == 0);
    CPPUNIT_ASSERT(block.getMultiTag("invalid_id") == false);
}