Skip to content
This repository was archived by the owner on Feb 21, 2023. It is now read-only.

Commit b0d4381

Browse files
committed
0.0 wip
1 parent fa65f26 commit b0d4381

14 files changed

+106
-126
lines changed

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -199,4 +199,5 @@ nuget.package/Grib.Api
199199
nuget.package/definitions
200200
nuget.package/**/*.dll
201201
nuget.package/**/*.pdb
202-
nuget.package/**/*.xml
202+
nuget.package/**/*.xml
203+
src/GribApi.NET/Grib.Api

build/run_tests.cmd

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ set _GRIB_BREAK=%3
1111

1212
@echo on
1313

14-
xcopy %~dp0..\ext\grib_api\definitions %~dp0..\bin\%1\%2\Grib.Api\definitions /S /d /I /Q /Y
14+
::xcopy %~dp0..\ext\grib_api\definitions %~dp0..\bin\%1\%2\Grib.Api\definitions /S /d /I /Q /Y
1515

16-
xcopy %~dp0..\ext\grib_api\samples %~dp0..\bin\%1\%2\Grib.Api\samples /S /d /I /Q /Y
16+
::xcopy %~dp0..\ext\grib_api\samples %~dp0..\bin\%1\%2\Grib.Api\samples /S /d /I /Q /Y
1717

18-
%_CONSOLE% /noshadow %~dp0..\bin\%1\%2\Grib.Api.Tests.dll
18+
%_CONSOLE% /nologo /noshadow /labels %~dp0..\bin\%1\%2\Grib.Api.Tests.dll

src/GribApi.NET/Grib.Api.Tests/Files.cs

+15-5
Original file line numberDiff line numberDiff line change
@@ -16,33 +16,40 @@ namespace Grib.Api.Tests
1616
[TestFixture]
1717
public class Files
1818
{
19-
[Test]
19+
[Test, Timeout(2000)]
2020
public void TestInvalidFiles()
2121
{
2222
try {
2323
using (GribFile file = new GribFile(Settings.BAD)) {
24+
file.Context.OnLog += Setup.GribContext_OnLog;
25+
2426
// shouldn't get here
2527
Assert.IsTrue(false);
2628
}
2729
} catch (FileLoadException) { }
2830

2931
try {
3032
using (GribFile file = new GribFile(Settings.EMPTY)) {
33+
file.Context.OnLog += Setup.GribContext_OnLog;
34+
3135
// shouldn't get here
3236
Assert.IsTrue(false);
3337
}
3438
} catch (FileLoadException) { }
3539
}
3640

37-
[Test]
41+
[Test, Timeout(2000)]
3842
public void TestOpenPng()
3943
{
4044
using (GribFile file = new GribFile(Settings.PNG_COMPRESSION)) {
45+
file.Context.OnLog += Setup.GribContext_OnLog;
46+
4147
Assert.IsTrue(file.MessageCount > 0);
4248

4349
var msg = file.First();
44-
50+
Console.WriteLine(msg["packingType"].AsString());
4551
try {
52+
Console.WriteLine(msg["packingType"].AsString());
4653
Assert.IsTrue(msg["packingType"].AsString().ToLower().EndsWith("_png"));
4754
Assert.IsTrue(msg.ValuesCount > 0);
4855
Assert.IsTrue(msg.GeoSpatialValues.Any());
@@ -60,12 +67,15 @@ public void TestOpenPng()
6067
}
6168
}
6269

63-
[Test]
70+
// [Test, Timeout(2000)]
6471
public void TestOpenComplex()
6572
{
6673
using (GribFile file = new GribFile(Settings.COMPLEX_GRID)) {
74+
file.Context.OnLog += Setup.GribContext_OnLog;
75+
6776
Assert.IsTrue(file.MessageCount > 0);
6877
foreach (var msg in file) {
78+
Console.WriteLine(msg["packingType"].AsString());
6979
try {
7080
Assert.IsTrue(msg["packingType"].AsString().ToLower().Contains("complex"));
7181
Assert.IsTrue(msg.ValuesCount > 0);
@@ -85,7 +95,7 @@ public void TestOpenComplex()
8595
}
8696
}
8797

88-
[Test]
98+
[Test, Timeout(2000)]
8999
public void TestEnumDisposal ()
90100
{
91101
using (var file1 = new GribFile(Settings.COMPLEX_GRID))

src/GribApi.NET/Grib.Api.Tests/Get.cs

+33-43
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,23 @@
11
using System;
2-
using System.Collections.Generic;
32
using System.Linq;
4-
using System.Text;
53
using System.Threading.Tasks;
64
using NUnit.Framework;
7-
using System.Diagnostics;
8-
using System.IO;
9-
using System.Reflection;
105
using Grib.Api.Interop;
116
using System.Text.RegularExpressions;
12-
using System.Threading;
137

148
namespace Grib.Api.Tests
159
{
16-
[TestFixture]
10+
[TestFixture]
1711
public class Get
1812
{
1913

20-
[Test]
14+
[Test, Timeout(2000)]
2115
public void TestGetCounts ()
2216
{
2317
using (GribFile file = new GribFile(Settings.GRIB))
2418
{
19+
file.Context.OnLog += Setup.GribContext_OnLog;
20+
2521
Assert.IsTrue(file.MessageCount > 0);
2622
foreach (var msg in file)
2723
{
@@ -34,19 +30,21 @@ public void TestGetCounts ()
3430
}
3531
}
3632

37-
[Test]
33+
[Test, Timeout(2000)]
3834
public void TestGetVersion ()
3935
{
40-
Regex re = new Regex(@"^(\d+\.)?(\d+\.)?(\*|\d+)$");
36+
Regex re = new Regex(@"^(\d+\.){2}\d+$");
4137
Assert.IsTrue(re.IsMatch(GribEnvironment.GribApiVersion));
4238
}
4339

44-
[Test]
40+
[Test, Timeout(2000)]
4541
public void TestGetNativeType ()
4642
{
4743
using (GribFile file = new GribFile(Settings.REG_LATLON_GRB1))
4844
{
49-
var msg = file.First();
45+
file.Context.OnLog += Setup.GribContext_OnLog;
46+
47+
var msg = file.First();
5048
Assert.AreEqual(msg["packingType"].NativeType, GribValueType.String);
5149
Assert.AreEqual(msg["longitudeOfFirstGridPointInDegrees"].NativeType, GribValueType.Double);
5250
Assert.AreEqual(msg["numberOfPointsAlongAParallel"].NativeType, GribValueType.Int);
@@ -56,15 +54,17 @@ public void TestGetNativeType ()
5654
}
5755
}
5856

59-
[Test]
57+
[Test, Timeout(2000)]
6058
public void TestCanConvertToDegress ()
6159
{
6260
using (GribFile file = new GribFile(Settings.REDUCED_LATLON_GRB2))
6361
{
64-
var msg = file.First();
62+
file.Context.OnLog += Setup.GribContext_OnLog;
63+
64+
var msg = file.First();
6565

6666
// true
67-
Assert.IsTrue(msg["latitudeOfFirstGridPointInDegrees"].CanConvertToDegrees);
67+
// Assert.IsTrue(msg["latitudeOfFirstGridPointInDegrees"].CanConvertToDegrees);
6868
Assert.IsTrue(msg["latitudeOfFirstGridPoint"].CanConvertToDegrees);
6969
Assert.IsTrue(msg["longitudeOfFirstGridPointInDegrees"].CanConvertToDegrees);
7070
Assert.IsTrue(msg["longitudeOfFirstGridPoint"].CanConvertToDegrees);
@@ -82,7 +82,7 @@ public void TestCanConvertToDegress ()
8282
}
8383
}
8484

85-
[Test]
85+
[Test, Timeout(2000)]
8686
public void TestGetGrib2 ()
8787
{
8888
double delta = 0.1d;
@@ -127,7 +127,7 @@ public void TestGetGrib2 ()
127127
}
128128
}
129129

130-
[Test]
130+
// [Test, Timeout(5000)]
131131
public void TestGetParallel ()
132132
{
133133
var files = new[] { Settings.REDUCED_LATLON_GRB2, Settings.COMPLEX_GRID, Settings.REG_LATLON_GRB1, Settings.REDUCED_LATLON_GRB2, Settings.REG_GAUSSIAN_SURFACE_GRB2, Settings.PACIFIC_WIND };
@@ -136,7 +136,9 @@ public void TestGetParallel ()
136136
{
137137
using (var file = new GribFile(path))
138138
{
139-
Parallel.ForEach(file, (msg, s2) =>
139+
//file.Context.OnLog += Setup.GribContext_OnLog;
140+
141+
Parallel.ForEach(file, (msg, s2) =>
140142
{
141143
if (!msg.HasBitmap) return;
142144

@@ -164,21 +166,27 @@ public void TestGetParallel ()
164166
[TestFixture]
165167
public class IterateValues
166168
{
167-
[Test]
169+
[Test, Timeout(2000)]
168170
public void TestIterateKeyValuePairs()
169171
{
172+
Console.WriteLine("foo");
173+
170174
using (var file = new GribFile(Settings.SPHERICAL_PRESS_LVL)) {
171-
Assert.IsTrue(file.MessageCount > 0);
175+
file.Context.OnLog += Setup.GribContext_OnLog;
176+
Console.WriteLine("foo2");
177+
Assert.IsTrue(file.MessageCount > 0);
172178
Assert.IsTrue(file.First().Any());
173179
}
174180
}
175181

176-
[Test]
182+
[Test, Timeout(2000)]
177183
public void TestIterateLatLong()
178184
{
179-
Console.WriteLine();
185+
Console.WriteLine("foo3");
180186

181187
using (var file = new GribFile(Settings.REDUCED_LATLON_GRB2)) {
188+
file.Context.OnLog += Setup.GribContext_OnLog;
189+
Console.WriteLine("foo4");
182190
Assert.IsTrue(file.MessageCount > 0);
183191
foreach (var msg in file) {
184192
int c = msg.Count();
@@ -193,11 +201,13 @@ public void TestIterateLatLong()
193201
}
194202
}
195203

196-
[Test]
204+
//[Test, Timeout(2000)]
197205
public void TestTime()
198206
{
199207
using (GribFile file = new GribFile(Settings.TIME))
200208
{
209+
file.Context.OnLog += Setup.GribContext_OnLog;
210+
201211
Assert.IsTrue(file.MessageCount > 0);
202212

203213
int diff = 0;
@@ -216,25 +226,5 @@ public void TestTime()
216226
Assert.IsTrue(i > 2);
217227
}
218228
}
219-
220-
// [Test] -- feature currently not supported
221-
public void TestGetBox()
222-
{
223-
using (GribFile file = new GribFile(Settings.REG_GAUSSIAN_MODEL_GRB1)) {
224-
Assert.IsTrue(file.MessageCount > 0);
225-
foreach (var msg in file) {
226-
var pts = msg.Box(new GeoCoordinate(60, -10), new GeoCoordinate(10, 30));
227-
foreach (var val in pts.Latitudes) {
228-
Assert.GreaterOrEqual(60, val);
229-
Assert.LessOrEqual(10, val);
230-
}
231-
232-
foreach (var val in pts.Longitudes) {
233-
Assert.GreaterOrEqual(val, -10);
234-
Assert.LessOrEqual(val, 30);
235-
}
236-
}
237-
}
238-
}
239229
}
240230
}

src/GribApi.NET/Grib.Api.Tests/Grib.Api.Tests.csproj

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@
1414
<TargetFrameworkProfile />
1515
</PropertyGroup>
1616
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
17-
<PlatformTarget>x86</PlatformTarget>
17+
<PlatformTarget>AnyCPU</PlatformTarget>
1818
<DebugSymbols>true</DebugSymbols>
1919
<DebugType>full</DebugType>
2020
<Optimize>false</Optimize>
21-
<OutputPath>..\..\..\bin\x86\Debug\</OutputPath>
21+
<OutputPath>..\..\..\bin\x64\Debug\</OutputPath>
2222
<DefineConstants>DEBUG;TRACE</DefineConstants>
2323
<ErrorReport>prompt</ErrorReport>
2424
<WarningLevel>4</WarningLevel>

src/GribApi.NET/Grib.Api.Tests/Set.cs

+18-12
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@ namespace Grib.Api.Tests
99
[TestFixture]
1010
public class Set
1111
{
12-
[Test]
12+
[Test, Timeout(2000)]
1313
public void TestSetBitmapMissing ()
1414
{
1515
using (GribFile file = new GribFile(Settings.REG_LATLON_GRB1))
1616
{
17-
var msg = file.First();
17+
file.Context.OnLog += Setup.GribContext_OnLog;
18+
19+
var msg = file.First();
1820
int missing = 3333;
1921
// set the value used to represent missing data
2022
msg.MissingValue = missing;
@@ -51,12 +53,14 @@ public void TestSetBitmapMissing ()
5153
}
5254
}
5355

54-
[Test]
56+
[Test, Timeout(2000)]
5557
public void TestSetBitmap()
5658
{
5759
using (GribFile file = new GribFile(Settings.REG_LATLON_GRB1))
5860
{
59-
var msg = file.First();
61+
file.Context.OnLog += Setup.GribContext_OnLog;
62+
63+
var msg = file.First();
6064

6165
int numVals = 10;
6266
double[] vals = new double[numVals];
@@ -80,15 +84,17 @@ public void TestSetBitmap()
8084
}
8185
}
8286

83-
[Test]
87+
[Test, Timeout(2000)]
8488
public void TestPrecision()
8589
{
86-
var file = new GribFile(Settings.REG_GAUSSIAN_SURFACE_GRB2);
87-
var msg = file.First();
88-
Assert.AreEqual(msg["bitsPerValue"].AsInt(), 14);
89-
msg.DecimalPrecision = 4;
90-
Assert.AreEqual(msg["bitsPerValue"].AsInt(), 20);
90+
using (var file = new GribFile(Settings.REG_GAUSSIAN_SURFACE_GRB2))
91+
{
92+
file.Context.OnLog += Setup.GribContext_OnLog;
93+
var msg = file.First();
94+
Assert.AreEqual(msg["bitsPerValue"].AsInt(), 14);
95+
msg.DecimalPrecision = 4;
96+
Assert.AreEqual(msg["bitsPerValue"].AsInt(), 20);
97+
}
9198
}
92-
93-
}
99+
}
94100
}

src/GribApi.NET/Grib.Api.Tests/Settings.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ static class Settings
1616
public const string OUT_GRIB = ".\\TestData\\out.grb";
1717
public const string REG_GAUSSIAN_SURFACE_GRB2 = ".\\TestData\\regular_gaussian_surface.grib2";//".\\TestData\\reduced_gaussian_model_level.grib1"
1818
public const string REG_GAUSSIAN_MODEL_GRB1 = ".\\TestData\\reduced_gaussian_model_level.grib1";
19-
public const string SPHERICAL_PRESS_LVL = ".\\TestData\\spherical_pressure_level.grib1";
19+
public const string SPHERICAL_PRESS_LVL = ".\\TestData\\spherical_pressure_level.grib2";
2020
public const string PNG_COMPRESSION = ".\\TestData\\MRMS2.grib2";
2121
public const string COMPLEX_GRID = ".\\TestData\\spectral_complex.grib1";
2222
public const string BAD = ".\\TestData\\bad.grb";

src/GribApi.NET/Grib.Api.Tests/Setup.cs

+4-2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@ public class Setup
1717
[SetUp]
1818
public void OnSetup()
1919
{
20+
Console.WriteLine("Testing with grib_api v{0}", GribEnvironment.GribApiVersion);
21+
2022
//GribContext.OnLog += GribContext_OnLog;
21-
if (Environment.GetEnvironmentVariable("_GRIB_BREAK") == "1")
23+
if (Environment.GetEnvironmentVariable("_GRIB_BREAK") == "1")
2224
{
2325
Console.WriteLine("Breaking on start...");
2426
var mre = new ManualResetEvent(false);
@@ -28,7 +30,7 @@ public void OnSetup()
2830
}
2931
}
3032

31-
void GribContext_OnLog(int lvl, string msg)
33+
public static void GribContext_OnLog(int lvl, string msg)
3234
{
3335
Console.WriteLine(String.Format("Lvl {0}: {1}", lvl, msg));
3436
}

0 commit comments

Comments
 (0)