Ejemplo n.º 1
0
void ConfigurationTest::parseHierarchic() {
    Configuration conf(Directory::join(CONFIGURATION_TEST_DIR, "hierarchic.conf"));
    conf.setFilename(Directory::join(CONFIGURATION_WRITE_TEST_DIR, "hierarchic.conf"));
    CORRADE_VERIFY(conf.isValid());

    /* Check parsing */
    CORRADE_VERIFY(conf.hasGroup("z"));
    CORRADE_COMPARE(conf.group("z")->group("x")->group("c")->group("v")->value("key1"), "val1");
    CORRADE_COMPARE(conf.groupCount("a"), 2);
    CORRADE_COMPARE(conf.group("a")->groupCount("b"), 2);
    CORRADE_COMPARE(conf.group("a")->group("b", 0)->value("key2"), "val2");
    CORRADE_COMPARE(conf.group("a")->group("b", 1)->value("key2"), "val3");
    CORRADE_COMPARE(conf.group("a", 1)->value("key3"), "val4");
    CORRADE_COMPARE(conf.group("a", 1)->group("b")->value("key2"), "val5");

    /* Expect no change */
    CORRADE_VERIFY(conf.save());
    CORRADE_COMPARE_AS(Directory::join(CONFIGURATION_WRITE_TEST_DIR, "hierarchic.conf"),
                       Directory::join(CONFIGURATION_TEST_DIR, "hierarchic.conf"),
                       TestSuite::Compare::File);

    /* Modify */
    conf.group("z")->group("x")->clear();
    conf.group("a", 1)->addGroup("b")->setValue("key2", "val6");
    conf.addGroup("q")->addGroup("w")->addGroup("e")->addGroup("r")->setValue("key4", "val7");

    /* Verify changes */
    CORRADE_VERIFY(conf.save());
    CORRADE_COMPARE_AS(Directory::join(CONFIGURATION_WRITE_TEST_DIR, "hierarchic.conf"),
                       Directory::join(CONFIGURATION_TEST_DIR, "hierarchic-modified.conf"),
                       TestSuite::Compare::File);
}
Ejemplo n.º 2
0
void QuaternionTest::rotation() {
    std::ostringstream o;
    Error::setOutput(&o);

    Vector3 axis(1.0f/Constants<Float>::sqrt3());

    CORRADE_COMPARE(Quaternion::rotation(Deg(-74.0f), {-1.0f, 2.0f, 2.0f}), Quaternion());
    CORRADE_COMPARE(o.str(), "Math::Quaternion::rotation(): axis must be normalized\n");

    Quaternion q = Quaternion::rotation(Deg(120.0f), axis);
    CORRADE_COMPARE(q.length(), 1.0f);
    CORRADE_COMPARE(q, Quaternion(Vector3(0.5f, 0.5f, 0.5f), 0.5f));
    CORRADE_COMPARE_AS(q.angle(), Deg(120.0f), Deg);
    CORRADE_COMPARE(q.axis(), axis);
    CORRADE_COMPARE(q.axis().length(), 1.0f);

    /* Verify negative angle */
    Quaternion q2 = Quaternion::rotation(Deg(-120.0f), axis);
    CORRADE_COMPARE(q2, Quaternion(Vector3(-0.5f, -0.5f, -0.5f), 0.5f));
    CORRADE_COMPARE_AS(q2.angle(), Deg(120.0f), Deg);
    CORRADE_COMPARE(q2.axis(), -axis);

    /* Default-constructed quaternion has zero angle and NaN axis */
    CORRADE_COMPARE_AS(Quaternion().angle(), Deg(0.0f), Deg);
    CORRADE_VERIFY(Quaternion().axis() != Quaternion().axis());
}
Ejemplo n.º 3
0
void StringTest::split() {
    /* Empty */
    CORRADE_COMPARE_AS(String::split({}, '/'),
        std::vector<std::string>{}, TestSuite::Compare::Container);
    CORRADE_COMPARE_AS(String::splitWithoutEmptyParts({}, '/'),
        std::vector<std::string>{}, TestSuite::Compare::Container);

    /* Only delimiter */
    CORRADE_COMPARE_AS(String::split("/", '/'),
        (std::vector<std::string>{"", ""}), TestSuite::Compare::Container);
    CORRADE_COMPARE_AS(String::splitWithoutEmptyParts("/", '/'),
        std::vector<std::string>{}, TestSuite::Compare::Container);

    /* No delimiters */
    CORRADE_COMPARE_AS(String::split("abcdef", '/'),
        std::vector<std::string>{"abcdef"}, TestSuite::Compare::Container);
    CORRADE_COMPARE_AS(String::splitWithoutEmptyParts("abcdef", '/'),
        std::vector<std::string>{"abcdef"}, TestSuite::Compare::Container);

    /* Common case */
    CORRADE_COMPARE_AS(String::split("ab/c/def", '/'),
        (std::vector<std::string>{"ab", "c", "def"}), TestSuite::Compare::Container);
    CORRADE_COMPARE_AS(String::splitWithoutEmptyParts("ab/c/def", '/'),
        (std::vector<std::string>{"ab", "c", "def"}), TestSuite::Compare::Container);

    /* Empty parts */
    CORRADE_COMPARE_AS(String::split("ab//c/def//", '/'),
        (std::vector<std::string>{"ab", "", "c", "def", "", ""}), TestSuite::Compare::Container);
    CORRADE_COMPARE_AS(String::splitWithoutEmptyParts("ab//c/def//", '/'),
        (std::vector<std::string>{"ab", "c", "def"}), TestSuite::Compare::Container);
}
Ejemplo n.º 4
0
void DdsImporterTest::rgbWithMips() {
    DdsImporter importer;
    CORRADE_VERIFY(importer.openFile(Utility::Directory::join(DDSIMPORTER_TEST_DIR, "rgb_uncompressed_mips.dds")));

    const char pixels[] = {'\xde', '\xad', '\xb5',
                           '\xca', '\xfe', '\x77',
                           '\xde', '\xad', '\xb5',
                           '\xca', '\xfe', '\x77',
                           '\xde', '\xad', '\xb5',
                           '\xca', '\xfe', '\x77'};
    const char mipPixels[] = {'\xd4', '\xd5', '\x96'};

    /* check image */
    std::optional<Trade::ImageData2D> image = importer.image2D(0);
    CORRADE_VERIFY(image);
    CORRADE_VERIFY(!image->isCompressed());
    CORRADE_COMPARE(image->storage().alignment(), 1);
    CORRADE_COMPARE(image->size(), Vector2i(3, 2));
    CORRADE_COMPARE(image->format(), PixelFormat::RGB);
    CORRADE_COMPARE(image->type(), PixelType::UnsignedByte);
    CORRADE_COMPARE_AS(image->data(), Containers::ArrayView<const char>(pixels),
            TestSuite::Compare::Container);

    /* check mip 0 */
    std::optional<Trade::ImageData2D> mip = importer.image2D(1);
    CORRADE_VERIFY(mip);
    CORRADE_VERIFY(!mip->isCompressed());
    CORRADE_COMPARE(image->storage().alignment(), 1);
    CORRADE_COMPARE(mip->size(), Vector2i{1});
    CORRADE_COMPARE(mip->format(), PixelFormat::RGB);
    CORRADE_COMPARE(mip->type(), PixelType::UnsignedByte);
    CORRADE_COMPARE_AS(mip->data(), Containers::ArrayView<const char>(mipPixels),
            TestSuite::Compare::Container);
}
Ejemplo n.º 5
0
void ConfigurationTest::typesScientific() {
    Configuration conf(Directory::join(CONFIGURATION_TEST_DIR, "types-scientific.conf"), Configuration::Flag::ReadOnly);

    CORRADE_COMPARE(conf.value<double>("exp"), 2.1e7);
    CORRADE_COMPARE(conf.value<double>("expPos"), 2.1e+7);
    conf.setValue("expPos", 2.1e+7, 0, ConfigurationValueFlag::Scientific);
    CORRADE_COMPARE(conf.value<double>("expNeg"), -2.1e7);
    CORRADE_COMPARE(conf.value<double>("expNeg2"), 2.1e-7);
    CORRADE_COMPARE(conf.value<double>("expBig"), 2.1E7);
    conf.setValue<double>("expBig", 2.1E7, 0, ConfigurationValueFlag::Scientific|ConfigurationValueFlag::Uppercase);

    /* Nothing should be changed after saving */
    CORRADE_VERIFY(conf.save(Directory::join(CONFIGURATION_WRITE_TEST_DIR, "types-scientific.conf")));

    /* MinGW32 has one zero more in scientific notation */
    #if !defined(__MINGW32__)
    CORRADE_COMPARE_AS(Directory::join(CONFIGURATION_WRITE_TEST_DIR, "types-scientific.conf"),
                       Directory::join(CONFIGURATION_TEST_DIR, "types-scientific.conf"),
                       TestSuite::Compare::File);
    #else
    CORRADE_COMPARE_AS(Directory::join(CONFIGURATION_WRITE_TEST_DIR, "types-scientific.conf"),
                       Directory::join(CONFIGURATION_TEST_DIR, "types-scientific-win.conf"),
                       TestSuite::Compare::File);
    #endif
}
Ejemplo n.º 6
0
void ResourceStaticTest::get() {
    Resource r("test");
    CORRADE_COMPARE_AS(r.get("predisposition.bin"),
                       Directory::join(RESOURCE_TEST_DIR, "predisposition.bin"),
                       TestSuite::Compare::StringToFile);
    CORRADE_COMPARE_AS(r.get("consequence.bin"),
                       Directory::join(RESOURCE_TEST_DIR, "consequence.bin"),
                       TestSuite::Compare::StringToFile);
}
Ejemplo n.º 7
0
void DualComplexTest::combinedTransformParts() {
    Vector2 translation = Vector2(-1.5f, 2.75f);
    DualComplex a = DualComplex::translation(translation)*DualComplex::rotation(Deg(23.0f));
    DualComplex b = DualComplex::rotation(Deg(23.0f))*DualComplex::translation(translation);

    CORRADE_COMPARE_AS(a.rotation().angle(), Deg(23.0f), Rad);
    CORRADE_COMPARE_AS(b.rotation().angle(), Deg(23.0f), Rad);
    CORRADE_COMPARE(a.translation(), translation);
    CORRADE_COMPARE(b.translation(), Complex::rotation(Deg(23.0f)).transformVector(translation));
}
Ejemplo n.º 8
0
void ConfigurationTest::parse() {
    Configuration conf(Directory::join(CONFIGURATION_TEST_DIR, "parse.conf"));
    conf.setFilename(Directory::join(CONFIGURATION_WRITE_TEST_DIR, "parse.conf"));
    CORRADE_VERIFY(conf.configuration() == &conf);
    CORRADE_VERIFY(conf.isValid());
    CORRADE_VERIFY(!conf.isEmpty());

    /* Groups */
    CORRADE_VERIFY(conf.hasGroups());
    CORRADE_COMPARE(conf.groupCount(), 4);
    CORRADE_VERIFY(!conf.hasGroup("groupNonexistent"));
    CORRADE_COMPARE(conf.groupCount("group"), 2);
    CORRADE_COMPARE(conf.groupCount("emptyGroup"), 1);
    CORRADE_VERIFY(conf.group("group")->configuration() == &conf);
    CORRADE_COMPARE_AS(conf.groups("group"),
        (std::vector<ConfigurationGroup*>{conf.group("group", 0), conf.group("group", 1)}),
        TestSuite::Compare::Container);

    std::string tmp;

    /* Values */
    CORRADE_VERIFY(conf.hasValues());
    CORRADE_COMPARE(conf.valueCount(), 1);
    CORRADE_VERIFY(conf.hasValue("key"));
    CORRADE_VERIFY(!conf.hasValue("keyNonexistent"));
    CORRADE_COMPARE(conf.value("key"), "value");
    CORRADE_COMPARE(conf.group("group", 1)->value("c", 1), "value5");
    CORRADE_COMPARE_AS(conf.group("group", 1)->values("c"),
        (std::vector<std::string>{"value4", "value5"}), TestSuite::Compare::Container);

    /* Default-constructed nonexistent values */
    CORRADE_COMPARE(conf.value("nonexistent"), "");
    CORRADE_COMPARE(conf.value<int>("nonexistent"), 0);
    CORRADE_COMPARE(conf.value<double>("nonexistent"), 0.0);

    /* Save file back - expecting no change */
    CORRADE_VERIFY(conf.save());

    /* Modify */
    conf.addValue("new", "value");
    conf.removeAllGroups("group");
    conf.group("thirdGroup")->clear();
    CORRADE_VERIFY(conf.removeGroup("emptyGroup"));
    CORRADE_VERIFY(conf.addGroup("newGroup"));
    conf.group("newGroup")->addValue("another", "value");
    conf.addGroup("newGroupCopy", new ConfigurationGroup(*conf.group("newGroup")));
    conf.removeAllValues("key");

    /* Save again, verify changes */
    CORRADE_VERIFY(conf.save());
    CORRADE_COMPARE_AS(Directory::join(CONFIGURATION_WRITE_TEST_DIR, "parse.conf"),
                       Directory::join(CONFIGURATION_TEST_DIR, "parse-modified.conf"),
                       TestSuite::Compare::File);
}
Ejemplo n.º 9
0
void DirectoryTest::write() {
    constexpr unsigned char data[] = {0xCA, 0xFE, 0xBA, 0xBE, 0x0D, 0x0A, 0x00, 0xDE, 0xAD, 0xBE, 0xEF};
    CORRADE_VERIFY(Directory::write(Directory::join(DIRECTORY_WRITE_TEST_DIR, "file"), data));
    CORRADE_COMPARE_AS(Directory::join(DIRECTORY_WRITE_TEST_DIR, "file"),
        Directory::join(DIRECTORY_TEST_DIR, "file"),
        TestSuite::Compare::File);

    CORRADE_VERIFY(Directory::writeString(Directory::join(DIRECTORY_WRITE_TEST_DIR, "file"),
        std::string("\xCA\xFE\xBA\xBE\x0D\x0A\x00\xDE\xAD\xBE\xEF", 11)));
    CORRADE_COMPARE_AS(Directory::join(DIRECTORY_WRITE_TEST_DIR, "file"),
        Directory::join(DIRECTORY_TEST_DIR, "file"),
        TestSuite::Compare::File);
}
Ejemplo n.º 10
0
void ComplexTest::rotation() {
    Complex a = Complex::rotation(Deg(120.0f));
    CORRADE_COMPARE(a.length(), 1.0f);
    CORRADE_COMPARE(a, Complex(-0.5f, 0.8660254f));
    CORRADE_COMPARE_AS(a.angle(), Deg(120.0f), Rad);

    /* Verify negative angle */
    Complex b = Complex::rotation(Deg(-240.0f));
    CORRADE_COMPARE(b, Complex(-0.5f, 0.8660254f));
    CORRADE_COMPARE_AS(b.angle(), Deg(120.0f), Rad);

    /* Default-constructed complex number has zero angle */
    CORRADE_COMPARE_AS(Complex().angle(), Deg(0.0f), Rad);
}
Ejemplo n.º 11
0
void Test::reloadPluginDirectory() {
    #if defined(CORRADE_TARGET_NACL_NEWLIB) || defined(CORRADE_TARGET_EMSCRIPTEN)
    CORRADE_SKIP("Plugin directory is irrelevant for static plugins");
    #else
    PluginManager::Manager<AbstractAnimal> manager(PLUGINS_DIR);

    /* Load Dog and rename the plugin */
    CORRADE_COMPARE(manager.load("Dog"), LoadState::Loaded);
    Directory::move(Directory::join(PLUGINS_DIR, std::string("Dog") + PLUGIN_FILENAME_SUFFIX),
                    Directory::join(PLUGINS_DIR, std::string("LostDog") + PLUGIN_FILENAME_SUFFIX));
    Directory::move(Directory::join(PLUGINS_DIR, "Dog.conf"),
                    Directory::join(PLUGINS_DIR, "LostDog.conf"));

    /* Rename Chihuahua */
    Directory::move(Directory::join(PLUGINS_DIR, std::string("Chihuahua") + PLUGIN_FILENAME_SUFFIX),
                    Directory::join(PLUGINS_DIR, std::string("LostChihuahua") + PLUGIN_FILENAME_SUFFIX));
    Directory::move(Directory::join(PLUGINS_DIR, "Chihuahua.conf"),
                    Directory::join(PLUGINS_DIR, "LostChihuahua.conf"));

    /* Reload plugin dir and check new name list */
    manager.reloadPluginDirectory();
    std::vector<std::string> actual1 = manager.pluginList();

    /* Unload Dog and it should disappear from the list */
    CORRADE_COMPARE(manager.unload("Dog"), LoadState::NotLoaded);
    manager.reloadPluginDirectory();
    std::vector<std::string> actual2 = manager.pluginList();

    /** @todo Also test that "WrongMetadataFile" plugins are reloaded */

    /* Rename everything back and clean up */
    Directory::move(Directory::join(PLUGINS_DIR, std::string("LostDog") + PLUGIN_FILENAME_SUFFIX),
                    Directory::join(PLUGINS_DIR, std::string("Dog") + PLUGIN_FILENAME_SUFFIX));
    Directory::move(Directory::join(PLUGINS_DIR, "LostDog.conf"),
                    Directory::join(PLUGINS_DIR, "Dog.conf"));

    Directory::move(Directory::join(PLUGINS_DIR, std::string("LostChihuahua") + PLUGIN_FILENAME_SUFFIX),
                    Directory::join(PLUGINS_DIR, std::string("Chihuahua") + PLUGIN_FILENAME_SUFFIX));
    Directory::move(Directory::join(PLUGINS_DIR, "LostChihuahua.conf"),
                    Directory::join(PLUGINS_DIR, "Chihuahua.conf"));

    manager.reloadPluginDirectory();

    /* And now we can safely compare */
    CORRADE_COMPARE_AS(actual1, (std::vector<std::string>{
        "Canary", "Dog", "LostChihuahua", "LostDog", "Snail"}), TestSuite::Compare::Container);
    CORRADE_COMPARE_AS(actual2, (std::vector<std::string>{
        "Canary", "LostChihuahua", "LostDog", "Snail"}), TestSuite::Compare::Container);
    #endif
}
Ejemplo n.º 12
0
void CylinderTest::wireframe() {
    Trade::MeshData3D cylinder = Cylinder::wireframe(2, 8, 0.5f);

    CORRADE_COMPARE_AS(cylinder.positions(0), (std::vector<Vector3>{
        {0.0f, -0.5f, 1.0f},
        {1.0f, -0.5f, 0.0f},
        {0.0f, -0.5f, -1.0f},
        {-1.0f, -0.5f, 0.0f},
        {0.707107f, -0.5f, 0.707107f},
        {0.707107f, -0.5f, -0.707107f},
        {-0.707107f, -0.5f, -0.707107f},
        {-0.707107f, -0.5f, 0.707107f},

        {0.0f, 0.0f, 1.0f},
        {1.0f, 0.0f, 0.0f},
        {0.0f, 0.0f, -1.0f},
        {-1.0f, 0.0f, 0.0f},
        {0.707107f, 0.0f, 0.707107f},
        {0.707107f, 0.0f, -0.707107f},
        {-0.707107f, 0.0f, -0.707107f},
        {-0.707107f, 0.0f, 0.707107f},

        {0.0f, 0.5f, 1.0f},
        {1.0f, 0.5f, 0.0f},
        {0.0f, 0.5f, -1.0f},
        {-1.0f, 0.5f, 0.0f},
        {0.707107f, 0.5f, 0.707107f},
        {0.707107f, 0.5f, -0.707107f},
        {-0.707107f, 0.5f, -0.707107f},
        {-0.707107f, 0.5f, 0.707107f}
    }), TestSuite::Compare::Container);

    CORRADE_COMPARE(cylinder.normalArrayCount(), 0);

    CORRADE_COMPARE_AS(cylinder.indices(), (std::vector<UnsignedInt>{
        0, 4, 1, 5, 2, 6, 3, 7,
        4, 1, 5, 2, 6, 3, 7, 0,

        0, 8, 1, 9, 2, 10, 3, 11,

        8, 12, 9, 13, 10, 14, 11, 15,
        12, 9, 13, 10, 14, 11, 15, 8,

        8, 16, 9, 17, 10, 18, 11, 19,

        16, 20, 17, 21, 18, 22, 19, 23,
        20, 17, 21, 18, 22, 19, 23, 16
    }), TestSuite::Compare::Container);
}
Ejemplo n.º 13
0
void BufferImageGLTest::constructCompressed() {
    const char data[] = { 'a', 0, 0, 0, 'b', 0, 0, 0 };
    CompressedBufferImage2D a{
        #ifndef MAGNUM_TARGET_GLES
        CompressedPixelStorage{}.setCompressedBlockSize(Vector3i{4}),
        #endif
        CompressedPixelFormat::RGBAS3tcDxt1,
        {4, 4}, data, BufferUsage::StaticDraw};

    #ifndef MAGNUM_TARGET_GLES
    const auto imageData = a.buffer().data();
    #endif

    MAGNUM_VERIFY_NO_ERROR();

    #ifndef MAGNUM_TARGET_GLES
    CORRADE_COMPARE(a.storage().compressedBlockSize(), Vector3i{4});
    #endif
    CORRADE_COMPARE(a.format(), CompressedPixelFormat::RGBAS3tcDxt1);
    CORRADE_COMPARE(a.size(), Vector2i(4, 4));
    CORRADE_COMPARE(a.dataSize(), 8);

    /** @todo How to verify the contents in ES? */
    #ifndef MAGNUM_TARGET_GLES
    CORRADE_COMPARE_AS(imageData, Containers::ArrayView<const char>{data},
                       TestSuite::Compare::Container);
    #endif
}
void TextureGLTest::subImageBuffer() {
    if(!Context::current()->isExtensionSupported<Extensions::GL::ARB::texture_rectangle>())
        CORRADE_SKIP(Extensions::GL::ARB::texture_rectangle::string() + std::string(" is not supported."));

    constexpr UnsignedByte zero[4*4*4] = {};
    constexpr UnsignedByte subData[] = { 0x00, 0x01, 0x02, 0x03,
                                         0x04, 0x05, 0x06, 0x07,
                                         0x08, 0x09, 0x0a, 0x0b,
                                         0x0c, 0x0d, 0x0e, 0x0f };
    RectangleTexture texture;
    texture.setImage(TextureFormat::RGBA8,
        ImageReference2D(ColorFormat::RGBA, ColorType::UnsignedByte, Vector2i(4), zero));
    texture.setSubImage(Vector2i(1),
        BufferImage2D(ColorFormat::RGBA, ColorType::UnsignedByte, Vector2i(2), subData, BufferUsage::StaticDraw));

    MAGNUM_VERIFY_NO_ERROR();

    BufferImage2D image(ColorFormat::RGBA, ColorType::UnsignedByte);
    texture.image(image, BufferUsage::StaticRead);
    const auto imageData = image.buffer().data<UnsignedByte>();

    MAGNUM_VERIFY_NO_ERROR();

    CORRADE_COMPARE(image.size(), Vector2i(4));
    CORRADE_COMPARE_AS(std::vector<UnsignedByte>(imageData.begin(), imageData.end()), (std::vector<UnsignedByte>{
        0, 0, 0, 0,    0,    0,    0,    0,    0,    0,    0,    0, 0, 0, 0, 0,
        0, 0, 0, 0, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0, 0, 0, 0,
        0, 0, 0, 0, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0, 0, 0, 0,
        0, 0, 0, 0,    0,    0,    0,    0,    0,    0,    0,    0, 0, 0, 0, 0
    }), TestSuite::Compare::Container);
}
void MagnumFontConverterTest::exportFont() {
    /* Remove previously created files */
    Utility::Directory::rm(Utility::Directory::join(MAGNUMFONTCONVERTER_TEST_WRITE_DIR, "font.conf"));
    Utility::Directory::rm(Utility::Directory::join(MAGNUMFONTCONVERTER_TEST_WRITE_DIR, "font.tga"));

    /* Open font */
    FreeTypeFont font;
    CORRADE_VERIFY(font.openFile(Utility::Directory::join(FREETYPEFONT_TEST_DIR, "Oxygen.ttf"), 16.0f));

    /* Create fake cache */
    MAGNUM_ASSERT_EXTENSION_SUPPORTED(Extensions::GL::ARB::texture_rg);
    GlyphCache cache(TextureFormat::R8, Vector2i(1536), Vector2i(256), Vector2i(24));
    cache.insert(font.glyphId(U'W'), {25, 34}, {{0, 8}, {16, 128}});
    cache.insert(font.glyphId(U'e'), {25, 12}, {{16, 4}, {64, 32}});

    /* Convert the file */
    MagnumFontConverter converter;
    converter.exportFontToFile(font, cache, Utility::Directory::join(MAGNUMFONTCONVERTER_TEST_WRITE_DIR, "font"), "Wave");

    /* Verify font parameters */
    /** @todo This might behave differently elsewhere due to unspecified order of glyphs in cache */
    CORRADE_COMPARE_AS(Utility::Directory::join(MAGNUMFONTCONVERTER_TEST_WRITE_DIR, "font.conf"),
                       Utility::Directory::join(MAGNUMFONT_TEST_DIR, "font.conf"),
                       TestSuite::Compare::File);

    /* Verify font image, no need to test image contents, as the image is garbage anyway */
    Trade::TgaImporter importer;
    CORRADE_VERIFY(importer.openFile(Utility::Directory::join(MAGNUMFONTCONVERTER_TEST_WRITE_DIR, "font.tga")));
    std::optional<Trade::ImageData2D> image = importer.image2D(0);
    CORRADE_VERIFY(image);
    CORRADE_COMPARE(image->size(), Vector2i(256));
    CORRADE_COMPARE(image->format(), ImageFormat::Red);
    CORRADE_COMPARE(image->type(), ImageType::UnsignedByte);
}
Ejemplo n.º 16
0
void Test::nameList() {
    #if !defined(CORRADE_TARGET_NACL_NEWLIB) && !defined(CORRADE_TARGET_EMSCRIPTEN)
    {
        PluginManager::Manager<AbstractAnimal> manager(PLUGINS_DIR);

        CORRADE_COMPARE_AS(manager.pluginList(), (std::vector<std::string>{
            "Canary", "Chihuahua", "Dog", "Snail"}), TestSuite::Compare::Container);
    }
    #endif

    /* Check if the list of dynamic plugins is cleared after destructing */
    PluginManager::Manager<AbstractAnimal> manager(Directory::join(PLUGINS_DIR, "nonexistent"));

    CORRADE_COMPARE_AS(manager.pluginList(), std::vector<std::string>{
        "Canary"}, TestSuite::Compare::Container);
}
Ejemplo n.º 17
0
void BufferImageGLTest::setData() {
    const char data[4] = { 'a', 'b', 'c', 'd' };
    BufferImage2D a{PixelStorage{}.setAlignment(1),
        PixelFormat::Red, PixelType::UnsignedByte, {4, 1}, data, BufferUsage::StaticDraw};

    const UnsignedShort data2[2*4] = { 1, 2, 3, 4, 5, 6, 7, 8 };
    a.setData(PixelFormat::RGBA, PixelType::UnsignedShort, {1, 2}, data2, BufferUsage::StaticDraw);

    #ifndef MAGNUM_TARGET_GLES
    const auto imageData = a.buffer().data<UnsignedShort>();
    #endif

    MAGNUM_VERIFY_NO_ERROR();

    CORRADE_COMPARE(a.storage().alignment(), 4);
    CORRADE_COMPARE(a.format(), PixelFormat::RGBA);
    CORRADE_COMPARE(a.type(), PixelType::UnsignedShort);
    CORRADE_COMPARE(a.size(), Vector2i(1, 2));

    /** @todo How to verify the contents in ES? */
    #ifndef MAGNUM_TARGET_GLES
    CORRADE_COMPARE_AS(imageData, Containers::ArrayView<const UnsignedShort>{data2},
                       TestSuite::Compare::Container);
    #endif
}
namespace Magnum { namespace Trade { namespace Test {

class AbstractImageConverterTest: public TestSuite::Tester {
    public:
        explicit AbstractImageConverterTest();

        void exportToFile();
};

AbstractImageConverterTest::AbstractImageConverterTest() {
    addTests({&AbstractImageConverterTest::exportToFile});
}

void AbstractImageConverterTest::exportToFile() {
    class DataExporter: public Trade::AbstractImageConverter {
        private:
            Features doFeatures() const override { return Feature::ConvertData; }

            Containers::Array<char> doExportToData(const ImageView2D& image) override {
                return Containers::Array<char>::from(char(image.size().x()), char(image.size().y()));
            };
    };

    /* Remove previous file */
    Utility::Directory::rm(Utility::Directory::join(TRADE_TEST_OUTPUT_DIR, "image.out"));

    /* doExportToFile() should call doExportToData() */
    DataExporter exporter;
    ImageView2D image(PixelFormat::RGBA, PixelType::UnsignedByte, {0xfe, 0xed}, {nullptr, 0xfe*0xed*4});
    CORRADE_VERIFY(exporter.exportToFile(image, Utility::Directory::join(TRADE_TEST_OUTPUT_DIR, "image.out")));
    CORRADE_COMPARE_AS(Utility::Directory::join(TRADE_TEST_OUTPUT_DIR, "image.out"),
        "\xFE\xED", TestSuite::Compare::FileToString);
}

}}}
Ejemplo n.º 19
0
void CubeMapTextureGLTest::subImageBuffer() {
    constexpr UnsignedByte zero[4*4*4] = {};
    constexpr UnsignedByte subData[] = { 0x00, 0x01, 0x02, 0x03,
                                         0x04, 0x05, 0x06, 0x07,
                                         0x08, 0x09, 0x0a, 0x0b,
                                         0x0c, 0x0d, 0x0e, 0x0f };
    CubeMapTexture texture;
    texture.setImage(CubeMapTexture::Coordinate::PositiveX, 0, TextureFormat::RGBA8,
        ImageReference2D(ColorFormat::RGBA, ColorType::UnsignedByte, Vector2i(4), zero));
    texture.setSubImage(CubeMapTexture::Coordinate::PositiveX, 0, Vector2i(1),
        BufferImage2D(ColorFormat::RGBA, ColorType::UnsignedByte, Vector2i(2), subData, BufferUsage::StaticDraw));

    MAGNUM_VERIFY_NO_ERROR();

    /** @todo How to test this on ES? */
    #ifndef MAGNUM_TARGET_GLES
    BufferImage2D image(ColorFormat::RGBA, ColorType::UnsignedByte);
    texture.image(CubeMapTexture::Coordinate::PositiveX, 0, image, BufferUsage::StaticRead);

    MAGNUM_VERIFY_NO_ERROR();

    CORRADE_COMPARE(image.size(), Vector2i(4));
    const auto imageData = image.buffer().data<UnsignedByte>();
    CORRADE_COMPARE_AS(std::vector<UnsignedByte>(imageData.begin(), imageData.end()), (std::vector<UnsignedByte>{
        0, 0, 0, 0,    0,    0,    0,    0,    0,    0,    0,    0, 0, 0, 0, 0,
        0, 0, 0, 0, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0, 0, 0, 0,
        0, 0, 0, 0, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0, 0, 0, 0,
        0, 0, 0, 0,    0,    0,    0,    0,    0,    0,    0,    0, 0, 0, 0, 0
    }), TestSuite::Compare::Container);
    #endif
}
Ejemplo n.º 20
0
void JpegImporterTest::rgb() {
    JpegImporter importer;
    CORRADE_VERIFY(importer.openFile(Utility::Directory::join(JPEGIMPORTER_TEST_DIR, "rgb.jpg")));

    std::optional<Trade::ImageData2D> image = importer.image2D(0);
    CORRADE_VERIFY(image);
    CORRADE_COMPARE(image->size(), Vector2i(3, 2));
    CORRADE_COMPARE(image->format(), PixelFormat::RGB);
    CORRADE_COMPARE(image->type(), PixelType::UnsignedByte);

    /* The image has four-byte aligned rows, clear the padding to deterministic
       values */
    CORRADE_COMPARE(image->data().size(), 24);
    image->data()[9] = image->data()[10] = image->data()[11] =
         image->data()[21] = image->data()[22] = image->data()[23] = 0;

    /* Data should be similar to the PNG */
    CORRADE_COMPARE_AS(image->data(), Containers::Array<char>::from(
        '\xca', '\xfe', '\x76',
        '\xdf', '\xad', '\xb6',
        '\xca', '\xfe', '\x76', 0, 0, 0,

        '\xe0', '\xad', '\xb6',
        '\xc9', '\xff', '\x76',
        '\xdf', '\xad', '\xb6', 0, 0, 0),
        TestSuite::Compare::Container<Containers::ArrayView<const char>>);
}
Ejemplo n.º 21
0
void ConfigurationTest::whitespaces() {
    Configuration conf(Directory::join(CONFIGURATION_TEST_DIR, "whitespaces.conf"));
    conf.setFilename(Directory::join(CONFIGURATION_WRITE_TEST_DIR, "whitespaces.conf"));
    conf.save();

    CORRADE_COMPARE_AS(Directory::join(CONFIGURATION_WRITE_TEST_DIR, "whitespaces.conf"),
                       Directory::join(CONFIGURATION_TEST_DIR, "whitespaces-saved.conf"),
                       TestSuite::Compare::File);
}
Ejemplo n.º 22
0
void WavImporterTest::mono16() {
    WavImporter importer;
    CORRADE_VERIFY(importer.openFile(Utility::Directory::join(WAVAUDIOIMPORTER_TEST_DIR, "mono16.wav")));

    CORRADE_COMPARE(importer.format(), Buffer::Format::Mono16);
    CORRADE_COMPARE(importer.frequency(), 44000);
    CORRADE_COMPARE_AS(importer.data(),
        Containers::Array<char>::from('\x1d', '\x10', '\x71', '\xc5'),
        TestSuite::Compare::Container);
}
Ejemplo n.º 23
0
void WavImporterTest::stereo8() {
    WavImporter importer;
    CORRADE_VERIFY(importer.openFile(Utility::Directory::join(WAVAUDIOIMPORTER_TEST_DIR, "stereo8.wav")));

    CORRADE_COMPARE(importer.format(), Buffer::Format::Stereo8);
    CORRADE_COMPARE(importer.frequency(), 96000);
    CORRADE_COMPARE_AS(importer.data(),
        Containers::Array<char>::from('\xde', '\xfe', '\xca', '\x7e'),
        TestSuite::Compare::Container);
}
Ejemplo n.º 24
0
void ConfigurationTest::truncate() {
    Configuration conf(Directory::join(CONFIGURATION_TEST_DIR, "parse.conf"), Configuration::Flag::ReadOnly|Configuration::Flag::Truncate);

    /* File is truncated on saving */
    CORRADE_VERIFY(conf.isValid());
    CORRADE_VERIFY(conf.isEmpty());
    CORRADE_VERIFY(conf.save(Directory::join(CONFIGURATION_WRITE_TEST_DIR, "truncate.conf")));
    CORRADE_COMPARE_AS(Directory::join(CONFIGURATION_WRITE_TEST_DIR, "truncate.conf"),
                       "", TestSuite::Compare::FileToString);
}
Ejemplo n.º 25
0
void ConfigurationTest::stripComments() {
    Configuration conf(Directory::join(CONFIGURATION_TEST_DIR, "comments.conf"), Configuration::Flag::SkipComments);
    conf.setFilename(Directory::join(CONFIGURATION_WRITE_TEST_DIR, "comments.conf"));

    /* Verify that comments were removed */
    CORRADE_VERIFY(conf.save());
    CORRADE_COMPARE_AS(Directory::join(CONFIGURATION_WRITE_TEST_DIR, "comments.conf"),
                       Directory::join(CONFIGURATION_TEST_DIR, "comments-saved.conf"),
                       TestSuite::Compare::File);
}
Ejemplo n.º 26
0
void CapsuleTest::wireframe2D() {
    Trade::MeshData2D capsule = Capsule2D::wireframe(2, 4, 0.5f);

    CORRADE_COMPARE_AS(capsule.positions(0), (std::vector<Vector2>{
        {0.0f, -1.5f},

        {-0.707107f, -1.20711f},
        {0.707107f, -1.20711f},

        {-1.0f, -0.5f},
        {1.0f, -0.5f},

        {-1.0f, -0.25f},
        {1.0f, -0.25f},

        {-1.0f, 0.0f},
        {1.0f, 0.0f},

        {-1.0f, 0.25f},
        {1.0f, 0.25f},

        {-1.0f, 0.5f},
        {1.0f, 0.5f},

        {-0.707107f, 1.20711f},
        {0.707107f, 1.20711f},

        {0.0f, 1.5f}
    }), TestSuite::Compare::Container);

    CORRADE_COMPARE_AS(capsule.indices(), (std::vector<UnsignedInt>{
        0, 1, 0, 2,

        1, 3, 2, 4,
        3, 5, 4, 6,
        5, 7, 6, 8,
        7, 9, 8, 10,
        9, 11, 10, 12,
        11, 13, 12, 14,

        13, 15, 14, 15
    }), TestSuite::Compare::Container);
}
Ejemplo n.º 27
0
void DualComplexTest::rotation() {
    DualComplex a = DualComplex::rotation(Deg(120.0f));
    CORRADE_COMPARE(a.length(), 1.0f);
    CORRADE_COMPARE(a, DualComplex({-0.5f, 0.8660254f}, {0.0f, 0.0f}));
    CORRADE_COMPARE_AS(a.rotation().angle(), Deg(120.0f), Rad);

    /* Constexpr access to rotation */
    constexpr DualComplex b({-1.0f, 2.0f}, {});
    constexpr Complex c = b.rotation();
    CORRADE_COMPARE(c, Complex(-1.0f, 2.0f));
}
Ejemplo n.º 28
0
void UVSphereTest::withTextureCoords() {
    Trade::MeshData3D sphere = UVSphere::solid(3, 3, UVSphere::TextureCoords::Generate);

    CORRADE_COMPARE_AS(*sphere.positions(0), (std::vector<Vector3>{
        {0.0f, -1.0f, 0.0f},

        {0.0f, -0.5f, 0.866025f},
        {0.75f, -0.5f, -0.433013f},
        {-0.75f, -0.5f, -0.433013f},
        {0.0f, -0.5f, 0.866025f},

        {0.0f, 0.5f, 0.866025f},
        {0.75f, 0.5f, -0.433013f},
        {-0.75f, 0.5f, -0.433013f},
        {0.0f, 0.5f, 0.866025f},

        {0.0f, 1.0f, 0.0f}
    }), TestSuite::Compare::Container);

    CORRADE_COMPARE_AS(*sphere.textureCoords2D(0), (std::vector<Vector2>{
        {0.5f, 0.0f},

        {0.0f, 0.333333f},
        {0.333333f, 0.333333f},
        {0.666667f, 0.333333f},
        {1.0f, 0.333333f},

        {0.0f, 0.666667f},
        {0.333333f, 0.666667f},
        {0.666667f, 0.666667f},
        {1.0f, 0.666667f},

        {0.5f, 1.0f}
    }), TestSuite::Compare::Container);

    CORRADE_COMPARE_AS(*sphere.indices(), (std::vector<UnsignedInt>{
        0, 2, 1, 0, 3, 2, 0, 4, 3,
        1, 2, 6, 1, 6, 5, 2, 3, 7, 2, 7, 6, 3, 4, 8, 3, 8, 7,
        5, 6, 9, 6, 7, 9, 7, 8, 9
    }), TestSuite::Compare::Container);
}
Ejemplo n.º 29
0
void UVSphereTest::wireframe() {
    Trade::MeshData3D sphere = UVSphere::wireframe(4, 8);

    CORRADE_COMPARE_AS(sphere.positions(0), (std::vector<Vector3>{
        {0.0f, -1.0f, 0.0f},

        {0.0f, -0.707107f, 0.707107f},
        {0.707107f, -0.707107f, 0.0f},
        {0.0f, -0.707107f, -0.707107f},
        {-0.707107f, -0.707107f, 0.0f},

        {0.0f, 0.0f, 1.0f},
        {1.0f, 0.0f, 0.0f},
        {0.0f, 0.0f, -1.0f},
        {-1.0f, 0.0f, 0.0f},
        {0.707107f, 0.0f, 0.707107f},
        {0.707107f, 0.0f, -0.707107f},
        {-0.707107f, 0.0f, -0.707107f},
        {-0.707107f, 0.0f, 0.707107f},

        {0.0f, 0.707107f, 0.707107f},
        {0.707107f, 0.707107f, 0.0f},
        {0.0f, 0.707107f, -0.707107f},
        {-0.707107f, 0.707107f, 0.0f},

        {0.0f, 1.0f, 0.0f}
    }), TestSuite::Compare::Container);

    CORRADE_COMPARE(sphere.normalArrayCount(), 0);

    CORRADE_COMPARE_AS(sphere.indices(), (std::vector<UnsignedInt>{
        0, 1, 0, 2, 0, 3, 0, 4,
        1, 5, 2, 6, 3, 7, 4, 8,

        5, 9, 6, 10, 7, 11, 8, 12,
        9, 6, 10, 7, 11, 8, 12, 5,

        5, 13, 6, 14, 7, 15, 8, 16,
        13, 17, 14, 17, 15, 17, 16, 17
    }), TestSuite::Compare::Container);
}
Ejemplo n.º 30
0
void StringTest::splitMultipleCharacters() {
    const std::string delimiters = ".:;";

    /* Empty */
    CORRADE_COMPARE_AS(String::splitWithoutEmptyParts({}, delimiters),
        std::vector<std::string>{}, TestSuite::Compare::Container);

    /* Only delimiters */
    CORRADE_COMPARE_AS(String::splitWithoutEmptyParts(".::;", delimiters),
        std::vector<std::string>{}, TestSuite::Compare::Container);

    /* No delimiters */
    CORRADE_COMPARE_AS(String::splitWithoutEmptyParts("abcdef", delimiters),
        std::vector<std::string>{"abcdef"}, TestSuite::Compare::Container);

    /* Common case */
    CORRADE_COMPARE_AS(String::splitWithoutEmptyParts("ab:c;def", delimiters),
        (std::vector<std::string>{"ab", "c", "def"}), TestSuite::Compare::Container);

    /* Empty parts */
    CORRADE_COMPARE_AS(String::splitWithoutEmptyParts("ab:c;;def.", delimiters),
        (std::vector<std::string>{"ab", "c", "def"}), TestSuite::Compare::Container);
}