Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MONDRIAN: Oops, missed a file; and there were some unkosher character…
…s in Excel.java. [git-p4: depot-paths = "//open/mondrian/": change = 10454]
- Loading branch information
1 parent
a8aaace
commit 3676c33
Showing
2 changed files
with
154 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,152 @@ | ||
/* | ||
// This software is subject to the terms of the Common Public License | ||
// Agreement, available at the following URL: | ||
// http://www.opensource.org/licenses/cpl.html. | ||
// Copyright (C) 2008-2008 Julian Hyde | ||
// All Rights Reserved. | ||
// You must accept the terms of that agreement to use this software. | ||
*/ | ||
package mondrian.olap.type; | ||
|
||
import mondrian.test.TestContext; | ||
import mondrian.olap.*; | ||
import junit.framework.TestCase; | ||
|
||
/** | ||
* Unit test for mondrian type facility. | ||
* | ||
* @author jhyde | ||
* @version $Id$ | ||
* @since Jan 17, 2008 | ||
*/ | ||
public class TypeTest extends TestCase { | ||
|
||
public void testConversions() { | ||
final Connection connection = TestContext.instance().getConnection(); | ||
Cube salesCube = null; | ||
for (Cube cube : connection.getSchema().getCubes()) { | ||
if (cube.getName().equals("Sales")) { | ||
salesCube = cube; | ||
} | ||
} | ||
assertTrue(salesCube != null); | ||
Dimension customersDimension = null; | ||
for (Dimension dimension : salesCube.getDimensions()) { | ||
if (dimension.getName().equals("Customers")) { | ||
customersDimension = dimension; | ||
} | ||
} | ||
assertTrue(customersDimension != null); | ||
Hierarchy hierarchy = customersDimension.getHierarchy(); | ||
Member member = hierarchy.getDefaultMember(); | ||
Level level = member.getLevel(); | ||
Type memberType = new MemberType( | ||
customersDimension, hierarchy, level, member); | ||
final LevelType levelType = | ||
new LevelType(customersDimension, hierarchy, level); | ||
final HierarchyType hierarchyType = | ||
new HierarchyType(customersDimension, hierarchy); | ||
final DimensionType dimensionType = | ||
new DimensionType(customersDimension); | ||
final StringType stringType = new StringType(); | ||
final ScalarType scalarType = new ScalarType(); | ||
final NumericType numericType = new NumericType(); | ||
final DateTimeType dateTimeType = new DateTimeType(); | ||
final DecimalType decimalType = new DecimalType(10, 2); | ||
final DecimalType integerType = new DecimalType(7, 0); | ||
final NullType nullType = new NullType(); | ||
final MemberType unknownMemberType = MemberType.Unknown; | ||
final TupleType tupleType = | ||
new TupleType( | ||
new Type[] {memberType, unknownMemberType}); | ||
final SetType tupleSetType = new SetType(tupleType); | ||
final SetType setType = new SetType(memberType); | ||
final LevelType unknownLevelType = LevelType.Unknown; | ||
final HierarchyType unknownHierarchyType = HierarchyType.Unknown; | ||
final DimensionType unknownDimensionType = DimensionType.Unknown; | ||
final BooleanType booleanType = new BooleanType(); | ||
Type[] types = { | ||
memberType, | ||
levelType, | ||
hierarchyType, | ||
dimensionType, | ||
numericType, | ||
dateTimeType, | ||
decimalType, | ||
integerType, | ||
scalarType, | ||
nullType, | ||
stringType, | ||
booleanType, | ||
tupleType, | ||
tupleSetType, | ||
setType, | ||
unknownDimensionType, | ||
unknownHierarchyType, | ||
unknownLevelType, | ||
unknownMemberType | ||
}; | ||
|
||
for (Type type : types) { | ||
// Check that each type is assignable to itself. | ||
final String desc = type.toString() + ":" + type.getClass(); | ||
assertEquals(desc, type, type.computeCommonType(type, null)); | ||
|
||
int[] conversionCount = {0}; | ||
assertEquals(desc, type, type.computeCommonType(type, conversionCount)); | ||
assertEquals(0, conversionCount[0]); | ||
|
||
// Check that each scalar type is assignable to nullable with zero | ||
// conversions. | ||
if (type instanceof ScalarType) { | ||
assertEquals(type, type.computeCommonType(nullType, null)); | ||
|
||
assertEquals(type, type.computeCommonType(nullType, conversionCount)); | ||
assertEquals(0, conversionCount[0]); | ||
} | ||
} | ||
|
||
for (Type fromType : types) { | ||
for (Type toType : types) { | ||
Type type = fromType.computeCommonType(toType, null); | ||
Type type2 = toType.computeCommonType(fromType, null); | ||
final String desc = | ||
"symmetric, from " + fromType + ", to " + toType; | ||
assertEquals(desc, type, type2); | ||
|
||
int[] conversionCount = {0}; | ||
int[] conversionCount2 = {0}; | ||
type = fromType.computeCommonType(toType, conversionCount); | ||
type2 = toType.computeCommonType(fromType, conversionCount2); | ||
if (conversionCount[0] == 0 | ||
&& conversionCount2[0] == 0) { | ||
assertEquals(desc, type, type2); | ||
} | ||
|
||
final int fromCategory = TypeUtil.typeToCategory(fromType); | ||
final int toCategory = TypeUtil.typeToCategory(toType); | ||
final int[] conversions = new int[] {0}; | ||
final boolean canConvert = | ||
TypeUtil.canConvert( | ||
fromCategory, | ||
toCategory, | ||
conversions); | ||
if (canConvert && conversions[0] == 0 && type == null) { | ||
if (!(fromType == memberType && toType == tupleType | ||
|| fromType == tupleSetType && toType == setType | ||
|| fromType == setType && toType == tupleSetType)) | ||
{ | ||
fail("can convert from " + fromType + " to " + toType | ||
+ ", but their most general type is null"); | ||
} | ||
} | ||
if (!canConvert && type != null && type.equals(toType)) { | ||
fail("cannot convert from " + fromType + " to " + toType | ||
+ ", but they have a most general type " + type); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
// End TypeTest.java |