Home | History | Annotate | Download | only in conformance
      1 /*******************************************************************************
      2  * Copyright 2011 See AUTHORS file.
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *   http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  ******************************************************************************/
     16 
     17 package com.badlogic.gdx.tests.conformance;
     18 
     19 import java.util.Arrays;
     20 
     21 import com.badlogic.gdx.Gdx;
     22 import com.badlogic.gdx.Graphics.DisplayMode;
     23 import com.badlogic.gdx.tests.utils.GdxTest;
     24 
     25 public class DisplayModeTest extends GdxTest {
     26 
     27 	@Override
     28 	public void create () {
     29 		DisplayMode displayMode = Gdx.graphics.getDisplayMode();
     30 		DisplayMode displayModeForMonitor = Gdx.graphics.getDisplayMode(Gdx.graphics.getMonitor());
     31 		DisplayMode[] displayModes = Gdx.graphics.getDisplayModes();
     32 		DisplayMode[] displayModesForMonitor = Gdx.graphics.getDisplayModes(Gdx.graphics.getMonitor());
     33 
     34 		Gdx.app.log("DisplayModeTest", "Display mode (using Gdx.graphics.getDisplayMode() ) : " + displayMode);
     35 		Gdx.app.log("DisplayModeTest",
     36 			"Display mode (using Gdx.graphics.getDisplayMode(Gdx.graphics.getMonitor()) ) : " + Arrays.toString(displayModes));
     37 		Gdx.app.log("DisplayModeTest",
     38 			"Display mode (using Gdx.graphics.getDisplayModes() ) : " + Arrays.toString(displayModesForMonitor));
     39 		Gdx.app.log("DisplayModeTest",
     40 			"Display mode (using Gdx.graphics.getDisplayModes(Gdx.graphics.getMonitor()) ): " + displayModeForMonitor);
     41 		assertDisplayModeEquals(displayMode, displayModeForMonitor);
     42 		assertDisplayModesEquals(displayModes, displayModesForMonitor);
     43 	}
     44 
     45 	void assertDisplayModesEquals (DisplayMode[] a, DisplayMode[] b) {
     46 		if (a.length == 0 || b.length == 0) throw new AssertionError("Argument a or b can't be a zero length array");
     47 		if (a.length != b.length) {
     48 			throw new AssertionError("Display modes " + Arrays.toString(a) + " aren't equal to display modes " + Arrays.toString(b));
     49 		}
     50 		boolean equal = true;
     51 		for (int i = 0; i < a.length; i++) {
     52 			equal = equal && isDisplayModeEqual(a[i], b[i]);
     53 		}
     54 		if (!equal) {
     55 			throw new AssertionError("Display modes " + Arrays.toString(a) + " aren't equal to display modes " + Arrays.toString(b));
     56 		}
     57 	}
     58 
     59 	void assertDisplayModeEquals (DisplayMode a, DisplayMode b) {
     60 		if (!isDisplayModeEqual(a, b)) {
     61 			throw new AssertionError(a + " isn't equal to " + b);
     62 		}
     63 	}
     64 
     65 	boolean isDisplayModeEqual (DisplayMode a, DisplayMode b) {
     66 		if (a == null || b == null) return false;
     67 		boolean equal = a.bitsPerPixel == b.bitsPerPixel && a.height == b.height && a.refreshRate == b.refreshRate
     68 			&& a.width == b.width;
     69 		return equal;
     70 	}
     71 
     72 }
     73