forked from supercollider/supercollider
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[hid_updates] TestHIDUsage : UnitTest {...}
- Loading branch information
1 parent
2a7689d
commit b4ea961
Showing
1 changed file
with
63 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
TestHIDUsage : UnitTest { | ||
classvar <usagePages; | ||
*initClass { | ||
usagePages = (Platform.resourceDir ++ "/HID_Support/hut/HidUsageTables.json").parseJSONFile["UsagePages"].select( | ||
{|page| | ||
((1..16) ++ [20, 64]).includes(page["Id"].asInteger) // TODO open this up to the full list of usages, including generated | ||
} | ||
); | ||
this.reportPasses=false; | ||
^super.initClass(); | ||
} | ||
formatName {|name| | ||
^name.asString.replace($ , "").asSymbol; | ||
} | ||
|
||
test_getUsageDescription_returnsPageNameAndUsageName { | ||
^usagePages.do({|page| | ||
page["UsageIds"].do({|usage| | ||
var expected = [this.formatName(page["Name"]), this.formatName(usage["Name"])]; | ||
var result = HIDUsage.getUsageDescription(page["Id"].asInteger, usage["Id"].asInteger); | ||
this.assertEquals(result, expected, | ||
"HIDUsage.getUsageDescription(%, %) should return %; got %".format( | ||
page["Id"], usage["Id"], expected, result | ||
)); | ||
}); | ||
}); | ||
} | ||
test_idsToName_GetsUsageName { | ||
^usagePages.do({|page| | ||
page["UsageIds"].do({|usage| | ||
var expected = this.formatName(usage["Name"]); | ||
var result = HIDUsage.idsToName(page["Id"].asInteger, usage["Id"].asInteger); | ||
this.assertEquals( | ||
result, | ||
expected, | ||
"HIDUsage.idsToName(%, %) should return usage name %; got %".format( | ||
page["Id"], usage["Id"], expected, result | ||
); | ||
); | ||
}); | ||
}); | ||
} | ||
test_getUsageIds_GetsUsage_Ids { | ||
^usagePages.do({|page| | ||
page["UsageIds"].do({|usage| | ||
var usageName = this.formatName(usage["Name"]); | ||
var expected = [page["Id"].asInteger, usage["Id"].asInteger]; | ||
var result = HIDUsage.getUsageIds(usageName); | ||
this.assertEquals( | ||
result, | ||
expected, | ||
"HIDUsage.getUsageIds(%) on page % should return %; got % (from page %)".format( | ||
usageName.cs, | ||
this.formatName(page["Name"]), | ||
expected.cs, | ||
result.cs, | ||
HIDUsage.performList(\getUsageDescription, result)[0] | ||
) | ||
) | ||
}); | ||
}) | ||
} | ||
} |