/* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file incorporates work covered by the following license notice: * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed * with this work for additional information regarding copyright * ownership. The ASF licenses this file to you under the Apache * License, Version 2.0 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/ package integration.forms;
publicclass RadioButtons extends complexlib.ComplexTestCase
{ private DocumentHelper m_document; /// our current test document private FormLayer m_formLayer; /// quick access to the form layer private XMultiServiceFactory m_orb; /// our service factory private XPropertySet m_primaryForm; /// the primary form, to be used in text documents and in the first page of spreadsheets private XPropertySet m_secondaryForm; /// the secondary form, to be used in the second page of spreadsheets
/* ------------------------------------------------------------------ */ /** this checks whether n groups of radio buttons, consisting of only one button each, * behave properly
*/ publicvoid checkSingleButtons() throws com.sun.star.uno.Exception, java.lang.Exception
{
prepareTestStep( false );
/* ------------------------------------------------------------------ */ /** creates three groups of radio buttons in a sample document, and checks whether they're working
*/ publicvoid checkThreeGroups( ) throws com.sun.star.uno.Exception, java.lang.Exception
{
prepareTestStep( false );
// switch to alive mode
m_document.getCurrentView( ).toggleFormDesignMode( );
// initially, after switching to alive mode, all buttons should be unchecked
verifySixPack( 0, 0, 0, 0, 0, 0 );
// check one button in every group
checkRadio( "group 1", "a" );
checkRadio( "group 2", "b" );
checkRadio( "group 3", "a" ); // and verify that this worked
verifySixPack( 1, 0, 0, 1, 1, 0 );
// check all buttons which are currently unchecked
checkRadio( "group 1", "b" );
checkRadio( "group 2", "a" );
checkRadio( "group 3", "b" ); // this should have reset the previous checks in the respective groups
verifySixPack( 0, 1, 1, 0, 0, 1 );
// and back to the previous check state
checkRadio( "group 1", "a" );
checkRadio( "group 2", "b" );
checkRadio( "group 3", "a" );
verifySixPack( 1, 0, 0, 1, 1, 0 );
cleanupTestStep();
}
/* ------------------------------------------------------------------ */ /** tests whether radio buttons which belong to different forms behave properly
*/ publicvoid checkMultipleForms( ) throws com.sun.star.uno.Exception, java.lang.Exception
{
prepareTestStep( false );
/* ------------------------------------------------------------------ */ /** tests for a special bug which we once had, where radio buttons lost their state after * switching spreadsheet pages
*/ publicvoid checkCalcPageSwitch( ) throws com.sun.star.uno.Exception, java.lang.Exception
{
prepareTestStep( true );
// see whether the check states on the first page survived the page switch
verifySheetRadios( 1, 0, 0, 1 ); // switch back to the first sheet, and see whether the check states survived
view.activateSheet( 0 );
verifySheetRadios( 1, 0, 0, 1 ); // and for completely, check again after switching to third sheet and back to the first
view.activateSheet( 2 );
view.activateSheet( 1 );
verifySheetRadios( 1, 0, 0, 1 );
/* ------------------------------------------------------------------ */ /** checks or unchecks the radio button (in our primary form) with the given name and the given ref value
*/ privatevoid checkRadio( String groupName, String refValue ) throws com.sun.star.uno.Exception, java.lang.Exception
{
checkRadio( groupName, refValue, m_primaryForm );
}
/* ------------------------------------------------------------------ */ /** checks or unchecks the radio button with the given name and the given ref value
*/ privatevoid checkRadio( String groupName, String refValue, XPropertySet form ) throws com.sun.star.uno.Exception, java.lang.Exception
{
XPropertySet xRadio = getRadioModel( groupName, refValue, form );
/* ------------------------------------------------------------------ */ /** verifies a number of radio buttons for their states
*/ privateboolean verifyRadios( XPropertySet[] radios, short[] expectedStates, String errorMessage ) throws com.sun.star.uno.Exception
{ short[] actualStates = newshort[radios.length];
// collect all current states. This is just to be able to emit them, in case of a failure for ( int i = 0; i<radios.length; ++i )
{
actualStates[i] = ((Short)radios[i].getPropertyValue( "State" )).shortValue();
}
// now actually check the states for ( int i = 0; i<radios.length; ++i )
{ if ( actualStates[i] != expectedStates[i] )
{
failed( errorMessage + " (expected: " + Arrays.toString( expectedStates ) + ", found: " + Arrays.toString( actualStates ) + ")" ); returnfalse;
}
}
returntrue;
}
/* ------------------------------------------------------------------ */ /** verifies the states of the 4 radio buttons from the checkSingleButtons test
*/ privateboolean verifySingleRadios( int state1, int state2, int state3, int state4 ) throws com.sun.star.uno.Exception, java.lang.Exception
{
XPropertySet[] radios = new XPropertySet[4];
radios[0] = getRadioModel( "group 1", "" );
radios[1] = getRadioModel( "group 2", "" );
radios[2] = getRadioModel( "group 3", "" );
radios[3] = getRadioModel( "group 4", "" );
return verifyRadios( radios, states, "single-group radio buttons do not work!" );
}
/* ------------------------------------------------------------------ */ /** verifies the states of 6 radio buttons form the checkThreeGroups test
*/ privateboolean verifySixPack( XPropertySet[] radios, String errorMessage, int state1, int state2, int state3, int state4, int state5, int state6 ) throws com.sun.star.uno.Exception, java.lang.Exception
{ short[] states = newshort[6];
states[0] = (short)state1;
states[1] = (short)state2;
states[2] = (short)state3;
states[3] = (short)state4;
states[4] = (short)state5;
states[5] = (short)state6;
/* ------------------------------------------------------------------ */ /** verifies the states of 6 radio buttons
*/ privateboolean verifySixPack( int state1, int state2, int state3, int state4, int state5, int state6 ) throws com.sun.star.uno.Exception, java.lang.Exception
{
XPropertySet[] radios = new XPropertySet[6];
radios[0] = getRadioModel( "group 1", "a" );
radios[1] = getRadioModel( "group 1", "b" );
radios[2] = getRadioModel( "group 2", "a" );
radios[3] = getRadioModel( "group 2", "b" );
radios[4] = getRadioModel( "group 3", "a" );
radios[5] = getRadioModel( "group 3", "b" );
return verifySixPack( radios, "six radio buttons, forming three different groups, do not properly work!",
state1, state2, state3, state4, state5, state6 );
}
/* ------------------------------------------------------------------ */ /** verifies the states of the 6 radio buttons in our checkMultipleForms test
*/ privateboolean verifyTwoFormRadios( int state1, int state2, int state3, int state4, int state5, int state6 ) throws com.sun.star.uno.Exception, java.lang.Exception
{
XPropertySet[] radios = new XPropertySet[6];
radios[0] = getRadioModel( "group 1", "a", m_primaryForm );
radios[1] = getRadioModel( "group 1", "b", m_primaryForm );
radios[2] = getRadioModel( "group 1", "c", m_primaryForm );
radios[3] = getRadioModel( "group 2", "a", m_secondaryForm );
radios[4] = getRadioModel( "group 2", "b", m_secondaryForm );
radios[5] = getRadioModel( "group 2", "c", m_secondaryForm );
return verifySixPack( radios, "radio buttons on different forms do not work properly!",
state1, state2, state3, state4, state5, state6 );
}
/* ------------------------------------------------------------------ */ /** verifies the states of the 4 radio buttons in our spreadsheet document (checkCalcPageSwitch)
*/ privateboolean verifySheetRadios( int state1, int state2, int state3, int state4 ) throws com.sun.star.uno.Exception, java.lang.Exception
{
XPropertySet[] radios = new XPropertySet[4];
radios[0] = getRadioModel( "group 1", "a", m_primaryForm );
radios[1] = getRadioModel( "group 1", "b", m_primaryForm );
radios[2] = getRadioModel( "group 2", "a", m_secondaryForm );
radios[3] = getRadioModel( "group 2", "b", m_secondaryForm );
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.