<commit_before>/*
 * Copyright 2011 <NAME>
 *
 * Licensed 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
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.syphr.mythtv.control;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import junit.framework.Assert;

import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.syphr.mythtv.control.test.Utils;
import org.syphr.mythtv.data.Channel;
import org.syphr.mythtv.data.Program;
import org.syphr.mythtv.test.Settings;
import org.syphr.mythtv.types.FrontendLocation;
import org.syphr.mythtv.types.Key;
import org.syphr.mythtv.types.SeekTarget;
import org.syphr.mythtv.types.Verbose;
import org.syphr.mythtv.util.exception.CommandException;
import org.syphr.prom.PropertiesManager;

public class ControlTest
{
    private static final Logger LOGGER = LoggerFactory.getLogger(ControlTest.class);

    private static PropertiesManager<Settings> settings;
    private static Control control;

    @BeforeClass
    public static void setUpBeforeClass() throws IOException
    {
        settings = Settings.createSettings();
        control = Utils.connect(settings);

        /*
         * Make sure the tests start at the main menu.
         */
        control.jump(FrontendLocation.MAIN_MENU);
    }

    @AfterClass
    public static void tearDownAfterClass() throws IOException
    {
        control.exit();
    }

    @Test
    public void testJump() throws IOException
    {
        control.jump(FrontendLocation.MYTH_VIDEO);
        control.jump(FrontendLocation.MAIN_MENU);
    }

    @Test
    public void testKey() throws IOException
    {
        control.key('m');
        control.key(Key.ESCAPE);
    }

    @Test(expected = CommandException.class)
    public void testPlayVolumeNotAllowed() throws IOException, CommandException
    {
        control.playVolume(10);
    }

    @Test(expected = CommandException.class)
    public void testPlayChannelUpNotAllowed() throws IOException, CommandException
    {
        control.playChannelUp();
    }

    @Test(expected = CommandException.class)
    public void testPlayChannelDownNotAllowed() throws IOException, CommandException
    {
        control.playChannelDown();
    }

    @Test(expected = CommandException.class)
    public void testPlayChannelNumberNotAllowed() throws IOException, CommandException
    {
        control.playChannel("10000000");
    }

    @Test(expected = CommandException.class)
    public void testPlayChannelIdNotAllowed() throws IOException, CommandException
    {
        control.playChannel(Integer.MAX_VALUE);
    }

    /*
     * This test is commented out because there is no way to retrieve a valid
     * myth:// URI or local filename through the frontend control socket.
     */
//    @Test
//    public void testPlayFile() throws IOException, CommandException
//    {
//        control.playFile("/tmp/test-file.mpg");
//        Utils.waitSeconds(10, "play file");
//    }

    @Test
    public void testPlayProgram() throws IOException, CommandException
    {
        List<Program> recordings = control.queryRecordings();
        if (recordings.isEmpty())
        {
            LOGGER.warn("Skipping play program test because no recordings were found");
            return;
        }

        Program recording = recordings.get(0);
        control.playProgram(recording.getChannel().getId(), recording.getRecStartTs(), false);
        Utils.waitSeconds(10, "play program");

        control.jump(FrontendLocation.MAIN_MENU);
    }

    @Test(expected = CommandException.class)
    public void testPlayProgramNotFound() throws IOException, CommandException
    {
        control.playProgram(Integer.MAX_VALUE, new Date(0), false);
    }

    @Test(expected = CommandException.class)
    public void testPlaySavePreviewNotAllowed() throws IOException, CommandException
    {
        control.playSavePreview();
    }

    @Test(expected = CommandException.class)
    public void testPlaySavePreviewFilenameNotAllowed() throws IOException, CommandException
    {
        control.playSavePreview("/tmp/preview-not-allowed-outside-playback.png");
    }

    @Test(expected = CommandException.class)
    public void testPlaySavePreviewFilenameSizeNotAllowed() throws IOException, CommandException
    {
        control.playSavePreview("/tmp/preview-not-allowed-outside-playback.png", 1280, 720);<commit_msg>added some extra sleeps to the main network control test<commit_after>/*
 * Copyright 2011 <NAME>
 *
 * Licensed 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
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.syphr.mythtv.control;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import junit.framework.Assert;

import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.syphr.mythtv.control.test.Utils;
import org.syphr.mythtv.data.Channel;
import org.syphr.mythtv.data.Program;
import org.syphr.mythtv.test.Settings;
import org.syphr.mythtv.types.FrontendLocation;
import org.syphr.mythtv.types.Key;
import org.syphr.mythtv.types.SeekTarget;
import org.syphr.mythtv.types.Verbose;
import org.syphr.mythtv.util.exception.CommandException;
import org.syphr.prom.PropertiesManager;

public class ControlTest
{
    private static final Logger LOGGER = LoggerFactory.getLogger(ControlTest.class);

    private static PropertiesManager<Settings> settings;
    private static Control control;

    @BeforeClass
    public static void setUpBeforeClass() throws IOException
    {
        settings = Settings.createSettings();
        control = Utils.connect(settings);

        /*
         * Make sure the tests start at the main menu.
         */
        control.jump(FrontendLocation.MAIN_MENU);
        Utils.waitSeconds(2, "jump to the main menu");
    }

    @AfterClass
    public static void tearDownAfterClass() throws IOException
    {
        control.exit();
    }

    @Test
    public void testJump() throws IOException
    {
        control.jump(FrontendLocation.MYTH_VIDEO);
        Utils.waitSeconds(2, "jump to myth video");
        control.jump(FrontendLocation.MAIN_MENU);
        Utils.waitSeconds(2, "jump to the main menu");
    }

    @Test
    public void testKey() throws IOException
    {
        control.key('m');
        Utils.waitSeconds(1, "show the context menu");
        control.key(Key.ESCAPE);
        Utils.waitSeconds(1, "escape the context menu");
    }

    @Test(expected = CommandException.class)
    public void testPlayVolumeNotAllowed() throws IOException, CommandException
    {
        control.playVolume(10);
    }

    @Test(expected = CommandException.class)
    public void testPlayChannelUpNotAllowed() throws IOException, CommandException
    {
        control.playChannelUp();
    }

    @Test(expected = CommandException.class)
    public void testPlayChannelDownNotAllowed() throws IOException, CommandException
    {
        control.playChannelDown();
    }

    @Test(expected = CommandException.class)
    public void testPlayChannelNumberNotAllowed() throws IOException, CommandException
    {
        control.playChannel("10000000");
    }

    @Test(expected = CommandException.class)
    public void testPlayChannelIdNotAllowed() throws IOException, CommandException
    {
        control.playChannel(Integer.MAX_VALUE);
    }

    /*
     * This test is commented out because there is no way to retrieve a valid
     * myth:// URI or local filename through the frontend control socket.
     */
//    @Test
//    public void testPlayFile() throws IOException, CommandException
//    {
//        control.playFile("/tmp/test-file.mpg");
//        Utils.waitSeconds(10, "play file");
//    }

    @Test
    public void testPlayProgram() throws IOException, CommandException
    {
        List<Program> recordings = control.queryRecordings();
        if (recordings.isEmpty())
        {
            LOGGER.warn("Skipping play program test because no recordings were found");
            return;
        }

        Program recording = recordings.get(0);
        control.playProgram(recording.getChannel().getId(), recording.getRecStartTs(), false);
        Utils.waitSeconds(10, "play program");

        control.jump(FrontendLocation.MAIN_MENU);
        Utils.waitSeconds(2, "jump to the main menu");
    }

    @Test(expected = CommandException.class)
    public void testPlayProgramNotFound() throws IOException, CommandException
    {
        control.playProgram(Integer.MAX_VALUE, new Date(0), false);
    }

    @Test(expected = CommandException.class)
    public void testPlaySavePreviewNotAllowed() throws IOException, CommandException
    {
        control.playSavePreview();
    }

    @Test(expected = CommandException.class)
    public void testPlaySavePreviewFilenameNotAllowed() throws IOException, CommandException
    {
        control.playSavePreview("/tmp/preview-not-allowed-outside-playback.png");
    }

    @Test(expected = CommandException.class)
    public void testPlaySavePreviewFilenameSizeNotAllowed() throws IOException, CommandException
    {
        control.playSavePreview("/tmp/preview-not-allowed-outside-playback.png", 1280, 720);
{'fraction_non_alphanumeric': 0.09460774771267276, 'fraction_numerical': 0.007007981312049835, 'mean_word_length': 3.3154136917261656, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3834028', 'n_tokens_mistral': 2880, 'n_tokens_neox': 2807, 'n_words': 719}