/** * Copyright © 2011 Canonical, Ltd. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ /** * Test rotation and rotation name helper functions. */ #include #include #include #include "XrandrUtils.h" /** * Lookup rotation names */ static void rotation_names(void) { Rotation normal = RR_Rotate_0; Rotation left = RR_Rotate_90; Rotation inverted = RR_Rotate_180; Rotation right = RR_Rotate_270; assert(0 == strcmp("normal", XRURotationName( normal ))); assert(0 == strcmp("left", XRURotationName( left ))); assert(0 == strcmp("inverted", XRURotationName( inverted ))); assert(0 == strcmp("right", XRURotationName( right ))); assert(0 == strcmp("left", XRURotationName( left | right ))); } /** * Verify that out of range name lookups produce an appropriate value or error */ static void rotation_names_invalid(void) { assert(0 == strcmp("normal", XRURotationName((Rotation) 0 ))); assert(0 == strcmp("normal", XRURotationName((Rotation) 1 << 5 ))); } /** * Lookup rotation indexes by their string name */ static void rotation_indexes_by_name(void) { assert(0 == XRUGetRotationIndex("normal")); assert(1 == XRUGetRotationIndex("left")); assert(2 == XRUGetRotationIndex("inverted")); assert(3 == XRUGetRotationIndex("right")); } /** * Verify garbage name lookups produce an appropriate error */ static void rotation_indexes_by_invalid_name(void) { assert(-1 == XRUGetRotationIndex(NULL)); assert(-1 == XRUGetRotationIndex("")); assert(-1 == XRUGetRotationIndex(" ")); assert(-1 == XRUGetRotationIndex("riight")); assert(-1 == XRUGetRotationIndex("invalid")); assert(-1 == XRUGetRotationIndex("NORMAL")); assert(-1 == XRUGetRotationIndex("uni©ode")); } /** * Check unterminated string behavior */ static void rotation_indexes_by_unterminated_name(void) { char left_unterminated[5] = "left"; left_unterminated[4] = ' '; assert(-1 == XRUGetRotationIndex(left_unterminated)); } /** * Lookup rotations by index */ static void rotations_by_index(void) { assert(RR_Rotate_0 == XRUGetRotation(0)); assert(RR_Rotate_90 == XRUGetRotation(1)); assert(RR_Rotate_180 == XRUGetRotation(2)); assert(RR_Rotate_270 == XRUGetRotation(3)); } /** * Verify out of range indexes produce appropriate errors */ static void rotations_by_invalid_index(void) { assert(0 == XRUGetRotation(-1)); assert(0 == XRUGetRotation( 4)); assert(0 == XRUGetRotation(42)); assert(0 == XRUGetRotation(-100)); } int main(int argc, char** argv) { rotation_names(); rotation_names_invalid(); rotation_indexes_by_name(); rotation_indexes_by_invalid_name(); rotation_indexes_by_unterminated_name(); rotations_by_index(); rotations_by_invalid_index(); return 0; }