Skip to content

Commit 645a003

Browse files
committed
autotest: simplify creation of MEM datasets
1 parent 72cb4dd commit 645a003

File tree

1 file changed

+18
-26
lines changed

1 file changed

+18
-26
lines changed

autotest/cpp/test_gdal.cpp

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "gdal.h"
2020
#include "tilematrixset.hpp"
2121
#include "gdalcachedpixelaccessor.h"
22+
#include "memdataset.h"
2223

2324
#include <algorithm>
2425
#include <array>
@@ -1283,8 +1284,8 @@ TEST_F(test_gdal, GDALDataTypeIsConversionLossy)
12831284
// Test GDALDataset::GetBands()
12841285
TEST_F(test_gdal, GDALDataset_GetBands)
12851286
{
1286-
GDALDatasetUniquePtr poDS(GDALDriver::FromHandle(GDALGetDriverByName("MEM"))
1287-
->Create("", 1, 1, 3, GDT_Byte, nullptr));
1287+
GDALDatasetUniquePtr poDS(
1288+
MEMDataset::Create("", 1, 1, 3, GDT_Byte, nullptr));
12881289
int nExpectedNumber = 1;
12891290
for (auto &&poBand : poDS->GetBands())
12901291
{
@@ -3318,8 +3319,7 @@ TEST_F(test_gdal, GetRasterNoDataReplacementValue)
33183319
TEST_F(test_gdal, GetIndexColorTranslationTo)
33193320
{
33203321
GDALDatasetUniquePtr poSrcDS(
3321-
GDALDriver::FromHandle(GDALGetDriverByName("MEM"))
3322-
->Create("", 1, 1, 1, GDT_Byte, nullptr));
3322+
MEMDataset::Create("", 1, 1, 1, GDT_Byte, nullptr));
33233323
{
33243324
GDALColorTable oCT;
33253325
{
@@ -3359,8 +3359,7 @@ TEST_F(test_gdal, GetIndexColorTranslationTo)
33593359
}
33603360

33613361
GDALDatasetUniquePtr poDstDS(
3362-
GDALDriver::FromHandle(GDALGetDriverByName("MEM"))
3363-
->Create("", 1, 1, 1, GDT_Byte, nullptr));
3362+
MEMDataset::Create("", 1, 1, 1, GDT_Byte, nullptr));
33643363
{
33653364
GDALColorTable oCT;
33663365
{
@@ -3470,8 +3469,7 @@ template <class T> void TestCachedPixelAccessor()
34703469
{
34713470
constexpr auto eType = GDALCachedPixelAccessorGetDataType<T>::DataType;
34723471
auto poDS = std::unique_ptr<GDALDataset>(
3473-
GDALDriver::FromHandle(GDALGetDriverByName("MEM"))
3474-
->Create("", 11, 23, 1, eType, nullptr));
3472+
MEMDataset::Create("", 11, 23, 1, eType, nullptr));
34753473
auto poBand = poDS->GetRasterBand(1);
34763474
GDALCachedPixelAccessor<T, 4> accessor(poBand);
34773475
for (int iY = 0; iY < poBand->GetYSize(); iY++)
@@ -3827,8 +3825,7 @@ TEST_F(test_gdal, GDALDeinterleave4ComponentsUInt16)
38273825
TEST_F(test_gdal, GDALDatasetReportError)
38283826
{
38293827
GDALDatasetUniquePtr poSrcDS(
3830-
GDALDriver::FromHandle(GDALGetDriverByName("MEM"))
3831-
->Create("", 1, 1, 1, GDT_Byte, nullptr));
3828+
MEMDataset::Create("", 1, 1, 1, GDT_Byte, nullptr));
38323829

38333830
CPLPushErrorHandler(CPLQuietErrorHandler);
38343831
poSrcDS->ReportError("foo", CE_Warning, CPLE_AppDefined, "bar");
@@ -4618,8 +4615,8 @@ TEST_F(test_gdal, gdal_gcp_class)
46184615

46194616
TEST_F(test_gdal, RasterIO_gdt_unknown)
46204617
{
4621-
GDALDatasetUniquePtr poDS(GDALDriver::FromHandle(GDALGetDriverByName("MEM"))
4622-
->Create("", 1, 1, 1, GDT_Float64, nullptr));
4618+
GDALDatasetUniquePtr poDS(
4619+
MEMDataset::Create("", 1, 1, 1, GDT_Float64, nullptr));
46234620
CPLErrorHandlerPusher oErrorHandler(CPLQuietErrorHandler);
46244621
GByte b = 0;
46254622
GDALRasterIOExtraArg sExtraArg;
@@ -4654,8 +4651,8 @@ TEST_F(test_gdal, CopyWords_gdt_unknown)
46544651
// Test GDALRasterBand::ReadRaster
46554652
TEST_F(test_gdal, ReadRaster)
46564653
{
4657-
GDALDatasetUniquePtr poDS(GDALDriver::FromHandle(GDALGetDriverByName("MEM"))
4658-
->Create("", 2, 3, 1, GDT_Float64, nullptr));
4654+
GDALDatasetUniquePtr poDS(
4655+
MEMDataset::Create("", 2, 3, 1, GDT_Float64, nullptr));
46594656
std::array<double, 6> buffer = {
46604657
-1e300, -1, //////////////////////////////////////////////
46614658
1, 128, //////////////////////////////////////////////
@@ -5056,8 +5053,8 @@ TEST_F(test_gdal, GDALComputeRasterMinMaxLocation)
50565053
// Test GDALComputeRasterMinMaxLocation
50575054
TEST_F(test_gdal, GDALComputeRasterMinMaxLocation_byte_min_max_optim)
50585055
{
5059-
GDALDatasetUniquePtr poDS(GDALDriver::FromHandle(GDALGetDriverByName("MEM"))
5060-
->Create("", 1, 4, 1, GDT_Byte, nullptr));
5056+
GDALDatasetUniquePtr poDS(
5057+
MEMDataset::Create("", 1, 4, 1, GDT_Byte, nullptr));
50615058
std::array<uint8_t, 4> buffer = {
50625059
1, //////////////////////////////////////////////////////////
50635060
0, //////////////////////////////////////////////////////////
@@ -5091,8 +5088,8 @@ TEST_F(test_gdal, GDALComputeRasterMinMaxLocation_byte_min_max_optim)
50915088
// Test GDALComputeRasterMinMaxLocation
50925089
TEST_F(test_gdal, GDALComputeRasterMinMaxLocation_with_mask)
50935090
{
5094-
GDALDatasetUniquePtr poDS(GDALDriver::FromHandle(GDALGetDriverByName("MEM"))
5095-
->Create("", 2, 2, 1, GDT_Byte, nullptr));
5091+
GDALDatasetUniquePtr poDS(
5092+
MEMDataset::Create("", 2, 2, 1, GDT_Byte, nullptr));
50965093
std::array<uint8_t, 6> buffer = {
50975094
2, 10, //////////////////////////////////////////////////////////
50985095
4, 20, //////////////////////////////////////////////////////////
@@ -5532,15 +5529,10 @@ TEST_F(test_gdal, GDALColorTable_from_qml_paletted)
55325529

55335530
TEST_F(test_gdal, GDALRasterBand_arithmetic_operators)
55345531
{
5535-
auto poMemDrv = GetGDALDriverManager()->GetDriverByName("MEM");
5536-
if (!poMemDrv)
5537-
{
5538-
GTEST_SKIP() << "MEM driver missing";
5539-
}
55405532
constexpr int WIDTH = 1;
55415533
constexpr int HEIGHT = 2;
55425534
auto poDS = std::unique_ptr<GDALDataset, GDALDatasetUniquePtrReleaser>(
5543-
poMemDrv->Create("", WIDTH, HEIGHT, 3, GDT_Float64, nullptr));
5535+
MEMDataset::Create("", WIDTH, HEIGHT, 3, GDT_Float64, nullptr));
55445536
std::array<double, 6> adfGT = {1, 2, 3, 4, 5, 6};
55455537
poDS->SetGeoTransform(adfGT.data());
55465538
OGRSpatialReference *poSRS = new OGRSpatialReference();
@@ -5560,7 +5552,7 @@ TEST_F(test_gdal, GDALRasterBand_arithmetic_operators)
55605552
{
55615553
auto poOtherDS =
55625554
std::unique_ptr<GDALDataset, GDALDatasetUniquePtrReleaser>(
5563-
poMemDrv->Create("", 1, 1, 1, GDT_Byte, nullptr));
5555+
MEMDataset::Create("", 1, 1, 1, GDT_Byte, nullptr));
55645556
EXPECT_THROW(
55655557
CPL_IGNORE_RET_VAL(firstBand + (*poOtherDS->GetRasterBand(1))),
55665558
std::runtime_error);
@@ -5877,7 +5869,7 @@ TEST_F(test_gdal, GDALRasterBand_arithmetic_operators)
58775869
{
58785870
auto poLogicalDS =
58795871
std::unique_ptr<GDALDataset, GDALDatasetUniquePtrReleaser>(
5880-
poMemDrv->Create("", WIDTH, HEIGHT, 2, GDT_Byte, nullptr));
5872+
MEMDataset::Create("", WIDTH, HEIGHT, 2, GDT_Byte, nullptr));
58815873
auto &trueBand = *(poLogicalDS->GetRasterBand(1));
58825874
auto &falseBand = *(poLogicalDS->GetRasterBand(2));
58835875
trueBand.Fill(true);

0 commit comments

Comments
 (0)