|
| 1 | +/* |
| 2 | + * Copyright (C) 2025 Open Source Robotics Foundation |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + * |
| 16 | +*/ |
| 17 | + |
| 18 | +#include <gtest/gtest.h> |
| 19 | +#include <memory> |
| 20 | + |
| 21 | +#include "gz/common/geospatial/HeightmapUtil.hh" |
| 22 | + |
| 23 | +#include "gz/common/testing/AutoLogFixture.hh" |
| 24 | +#include "gz/common/testing/TestPaths.hh" |
| 25 | + |
| 26 | +using namespace gz; |
| 27 | + |
| 28 | +class HeightmapLoaderTest : public common::testing::AutoLogFixture { }; |
| 29 | + |
| 30 | +///////////////////////////////////////////////// |
| 31 | +TEST_F(HeightmapLoaderTest, SupportedImageHeightmapFileExtension) |
| 32 | +{ |
| 33 | + EXPECT_TRUE(common::isSupportedImageHeightmapFileExtension("f.jpg")); |
| 34 | + EXPECT_TRUE(common::isSupportedImageHeightmapFileExtension("f.jpeg")); |
| 35 | + EXPECT_TRUE(common::isSupportedImageHeightmapFileExtension("f.png")); |
| 36 | + EXPECT_TRUE(common::isSupportedImageHeightmapFileExtension("f.JPG")); |
| 37 | + EXPECT_TRUE(common::isSupportedImageHeightmapFileExtension("f.JPEG")); |
| 38 | + EXPECT_TRUE(common::isSupportedImageHeightmapFileExtension("f.PNG")); |
| 39 | + EXPECT_TRUE(common::isSupportedImageHeightmapFileExtension(".PNG")); |
| 40 | + EXPECT_FALSE(common::isSupportedImageHeightmapFileExtension("f.tiff")); |
| 41 | + EXPECT_FALSE(common::isSupportedImageHeightmapFileExtension("invalid")); |
| 42 | + EXPECT_FALSE(common::isSupportedImageHeightmapFileExtension("")); |
| 43 | +} |
| 44 | + |
| 45 | +///////////////////////////////////////////////// |
| 46 | +TEST_F(HeightmapLoaderTest, LoadImage) |
| 47 | +{ |
| 48 | + const auto path = common::testing::TestFile("data", "heightmap_bowl.png"); |
| 49 | + std::unique_ptr<common::HeightmapData> data = |
| 50 | + common::loadHeightmapData(path); |
| 51 | + EXPECT_NE(nullptr, data); |
| 52 | +} |
| 53 | + |
| 54 | +///////////////////////////////////////////////// |
| 55 | +TEST_F(HeightmapLoaderTest, LoadDEM) |
| 56 | +{ |
| 57 | + const auto path = common::testing::TestFile("data", "dem_squared.tif"); |
| 58 | + std::unique_ptr<common::HeightmapData> data = |
| 59 | + common::loadHeightmapData(path); |
| 60 | + EXPECT_NE(nullptr, data); |
| 61 | +} |
| 62 | + |
| 63 | +///////////////////////////////////////////////// |
| 64 | +TEST_F(HeightmapLoaderTest, LoadInvalidFile) |
| 65 | +{ |
| 66 | + EXPECT_EQ(nullptr, common::loadHeightmapData("invalid/file.jpg")); |
| 67 | + EXPECT_EQ(nullptr, common::loadHeightmapData("invalid/file_no_extension")); |
| 68 | +} |
0 commit comments