Skip to content

Commit 6821751

Browse files
author
Ayla Khan
committed
Add remaining input checks to algorithm clean up. More testing.
1 parent 3c71d7b commit 6821751

File tree

2 files changed

+38
-47
lines changed

2 files changed

+38
-47
lines changed

src/Core/Algorithms/Field/Tests/GetFieldDataAlgoTests.cc

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,21 @@ last change: 04/10/2014
4040

4141
using namespace SCIRun::Core::Geometry;
4242
using namespace SCIRun::Core::Algorithms::Fields;
43+
using namespace SCIRun::Core::Algorithms;
44+
45+
TEST(GetFieldDataTest, NullInputThrowsException)
46+
{
47+
GetFieldDataAlgo algo;
48+
FieldHandle nullField;
49+
50+
ASSERT_THROW(algo.run(nullField), AlgorithmInputException);
51+
}
52+
53+
TEST(GetFieldDataTest, DISABLED_FieldNoDataThrowsException)
54+
{
55+
// TODO: test field with type set to nodata (should throw AlgorithmInputException)
56+
FAIL() << "TODO";
57+
}
4358

4459
TEST(GetFieldDataTest, TriSurfOnNodeScalar)
4560
{

src/Core/Algorithms/Legacy/Fields/FieldData/GetFieldData.cc

Lines changed: 23 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -68,62 +68,38 @@ AlgorithmOutput GetFieldDataAlgo::run_generic(const AlgorithmInput& input) const
6868
/// Function call to convert data from Field into Matrix data
6969
DenseMatrixHandle GetFieldDataAlgo::run(FieldHandle input_field) const
7070
{
71-
#ifdef SCIRUN4_CODE_TO_BE_ENABLED_LATER
72-
algo_start("GetFieldData");
73-
74-
/// Check whether we have a field.
75-
if (input.get_rep() == 0)
76-
{
77-
error("No input source field");
78-
algo_end(); return (false);
79-
}
80-
81-
/// Construct a class with all the type information of this field
82-
FieldInformation fi(input);
83-
84-
/// Check whether we have data
85-
if (fi.is_nodata())
71+
if (!input_field)
8672
{
87-
error("Field does not contain any data");
88-
algo_end(); return (false);
73+
THROW_ALGORITHM_INPUT_ERROR("No input field was provided");
8974
}
90-
91-
/// Depending on the data type select a sub algorithm
92-
if (fi.is_scalar())
93-
return(GetScalarFieldDataV(this,input,output));
9475

95-
else if (fi.is_vector())
96-
return(GetVectorFieldDataV(this,input,output));
76+
DenseMatrixHandle output;
9777

98-
else if (fi.is_tensor())
99-
return(GetTensorFieldDataV(this,input,output));
100-
101-
error("Unknown data type");
102-
algo_end(); return (false);
103-
#endif
104-
105-
DenseMatrixHandle output;
106-
10778
VField* vfield1 = input_field->vfield();
10879

10980
/// Check whether we have data
110-
if (!input_field || !vfield1)
81+
if (! vfield1)
11182
{
112-
THROW_ALGORITHM_INPUT_ERROR("Could not obtain input field");
83+
THROW_ALGORITHM_INPUT_ERROR("Could not obtain VField interface");
11384
}
114-
115-
if (vfield1->is_scalar())
116-
return (GetScalarFieldDataV(input_field));
85+
86+
if (vfield1->is_nodata())
87+
{
88+
THROW_ALGORITHM_INPUT_ERROR("Invalid input field (no data)");
89+
}
90+
91+
if (vfield1->is_scalar())
92+
return (GetScalarFieldDataV(input_field));
11793
else
118-
if (vfield1->is_vector())
119-
return (GetVectorFieldDataV(input_field));
94+
if (vfield1->is_vector())
95+
return (GetVectorFieldDataV(input_field));
12096
else
121-
if (vfield1->is_tensor())
122-
return (GetTensorFieldDataV(input_field));
123-
else
124-
{
125-
THROW_ALGORITHM_INPUT_ERROR("Unknown field data type!");
126-
}
97+
if (vfield1->is_tensor())
98+
return (GetTensorFieldDataV(input_field));
99+
else
100+
{
101+
THROW_ALGORITHM_INPUT_ERROR("Unknown field data type!");
102+
}
127103

128104
}
129105

@@ -150,7 +126,7 @@ DenseMatrixHandle GetFieldDataAlgo::GetScalarFieldDataV(FieldHandle& input) cons
150126
{
151127
vfield->get_value((*output)(idx, 0),idx);
152128
}
153-
#ifdef SCIRUN4_CODE_TO_BE_ENABLED_LATER
129+
#ifdef SCIRUN4_CODE_TO_BE_ENABLED_LATER
154130
if (vfield->basis_order() == 2)
155131
{
156132
vfield->vmesh()->synchronize(Mesh::EDGES_E);
@@ -159,7 +135,7 @@ DenseMatrixHandle GetFieldDataAlgo::GetScalarFieldDataV(FieldHandle& input) cons
159135
vfield->get_evalue((*output)(idx, 0),idx);
160136
}
161137
}
162-
#endif
138+
#endif
163139

164140
return output;
165141
}

0 commit comments

Comments
 (0)