Skip to content

Commit

Permalink
Linux test failure debugging.
Browse files Browse the repository at this point in the history
  • Loading branch information
metasim committed Sep 28, 2022
1 parent cb1a814 commit df79fbb
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 17 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ on:
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

env:
RUST_BACKTRACE: 1

jobs:
gdal_35:
name: "ci gdal-35"
Expand Down
2 changes: 1 addition & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
- Added ability to set color table for bands with palette color interpretation.
Added ability to create a color ramp (interpolated) color table.

- <>
- <https://github.com/georust/gdal/pull/314>

## 0.13

Expand Down
9 changes: 8 additions & 1 deletion src/dataset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ use crate::{
Driver, Metadata,
};

use gdal_sys::OGRGeometryH;
use gdal_sys::{
self, CPLErr, GDALAccess, GDALDatasetH, GDALMajorObjectH, OGRErr, OGRLayerH, OGRwkbGeometryType,
};
use gdal_sys::{GDALFlushCache, OGRGeometryH};
use libc::{c_double, c_int, c_uint};

#[cfg(all(major_ge_3, minor_ge_1))]
Expand Down Expand Up @@ -400,6 +400,13 @@ impl Dataset {
Ok(Dataset { c_dataset })
}

/// Flush all write cached data to disk.
///
/// See [`GDALFlushCache`].
pub fn flush_cache(&self) {
unsafe { GDALFlushCache(self.c_dataset) }
}

/// Creates a new Dataset by wrapping a C pointer
///
/// # Safety
Expand Down
26 changes: 11 additions & 15 deletions src/raster/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ use crate::Driver;
use gdal_sys::GDALDataType;
use std::path::Path;

use crate::errors::GdalError;
#[cfg(feature = "ndarray")]
use ndarray::arr2;

Expand Down Expand Up @@ -810,13 +809,13 @@ fn test_color_table() {
}

#[test]
fn test_create_color_table() -> crate::errors::Result<()> {
fn test_create_color_table() {
let fixture = TempFixture::fixture("labels.tif");
// Open, modify, then close the base file.
{
let dataset = Dataset::open(&fixture)?;
let dataset = Dataset::open(&fixture).unwrap();
assert_eq!(dataset.raster_count(), 1);
let mut band = dataset.rasterband(1)?;
let mut band = dataset.rasterband(1).unwrap();
assert_eq!(band.band_type(), GDALDataType::GDT_Byte);
assert!(band.color_table().is_none());

Expand All @@ -831,31 +830,28 @@ fn test_create_color_table() -> crate::errors::Result<()> {
assert_eq!(ct.entry(8), None);

band.set_color_table(&ct);
dataset.flush_cache();
drop(dataset);
}

// Reopen to confirm the changes.
let dataset = Dataset::open(&fixture)?;
let band = dataset.rasterband(1)?;
let ct = band
.color_table()
.ok_or_else(|| GdalError::BadArgument("missing color table".into()))?;
let dataset = Dataset::open(&fixture).unwrap();
let band = dataset.rasterband(1).unwrap();
let ct = band.color_table().expect("saved color table");

assert_eq!(ct.entry_count(), 8);
assert_eq!(ct.entry(0), Some(ColorEntry::rgba(0, 0, 0, 0)));
assert_eq!(ct.entry(2), Some(ColorEntry::rgba(255, 0, 0, 255)));
assert_eq!(ct.entry(8), None);

Ok(())
}

#[test]
fn test_color_ramp() -> crate::errors::Result<()> {
let ct = ColorTable::color_ramp(0, &ColorEntry::grey(0), 99, &ColorEntry::grey(99))?;
fn test_color_ramp() {
let ct = ColorTable::color_ramp(0, &ColorEntry::grey(0), 99, &ColorEntry::grey(99)).unwrap();
assert_eq!(ct.entry(0), Some(ColorEntry::grey(0)));
assert_eq!(ct.entry(57), Some(ColorEntry::grey(57)));
assert_eq!(ct.entry(99), Some(ColorEntry::grey(99)));
assert_eq!(ct.entry(100), None);

Ok(())
}

#[test]
Expand Down

0 comments on commit df79fbb

Please sign in to comment.