Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added option to select and force the default renderer.

  • Loading branch information...
commit b12ac37c1e5ddbc807065fa3ecc4a50699229d73 1 parent 83e0894
@Raptor399 Raptor399 authored
View
1  CHANGELOG
@@ -12,6 +12,7 @@ Changelog:
Language updates:
- added Arabic
- added Hebrew (thanks, zvi-yamin!)
+ Added option to select and force the default renderer
1.52.1 - 2012-04-06
View
17 src/main/external-resources/PMS.conf
@@ -150,6 +150,19 @@ maximumbitrate = 110
# the server hibernating or sleeping while it is streaming data.
#prevents_sleep_mode = false
+# GUI Option: Default renderer when automatic detection fails (selector)
+# PMS can recognize many renderers automatically. Sometimes a renderer will
+# connect the PMS does not recognize. This option defines which renderer PMS
+# should assume. Default value is empty, which means PMS will assume the
+# "Unknown renderer".
+#renderer_default =
+
+# GUI Option: Force default renderer (disable automatic detection) (toggle)
+# By default PMS tries to automatically detect what renderers try to connect
+# to it. By settings this option to true, PMS will assume any renderer that
+# connects is the default renderer.
+#renderer_force_default = false
+
# ---< Plugins >--------------------------------------------------------------
#
# incomplete - no information available
@@ -164,7 +177,7 @@ maximumbitrate = 110
# Generate Thumbnails
# -------------------
# GUI Option: Generate Thumbnails
-# Set whether or not to generate thumbnails of medai files for the client.
+# Set whether or not to generate thumbnails of media files for the client.
thumbnails = true
# Thumbnail seeking position
@@ -318,7 +331,7 @@ folders =
# ----------------------------------------------------------------------------
-# Transconder Settings
+# Transcoder Settings
# ----------------------------------------------------------------------------
# Transcoder engines
View
11 src/main/external-resources/documentation/general_configuration.html
@@ -82,6 +82,17 @@
<dt>Prevent OS from sleeping when streaming</dt>
<dd>Checking this checkbox will make sure that the computer will
not go to standby mode while streaming.</dd>
+
+ <dt>Default renderer when automatic detection fails</dt>
+ <dd>PMS can recognize many renderers automatically. Sometimes a renderer will
+ connect the PMS does not recognize. This option defines which renderer PMS
+ should assume.</dd>
+
+ <dt>Force default renderer (disable automatic detection)</dt>
+ <dd>By default PMS tries to automatically detect what renderers try to connect
+ to it. By settings this option to true, PMS will assume any renderer that
+ connects is the default renderer.</dd>
+
</dl>
View
2  src/main/java/net/pms/PMS.java
@@ -393,7 +393,7 @@ public void configurationChanged(ConfigurationEvent event) {
logger.info("Profile name: " + configuration.getProfileName());
logger.info("");
- RendererConfiguration.loadRendererConfigurations();
+ RendererConfiguration.loadRendererConfigurations(configuration);
logger.info("Checking MPlayer font cache. It can take a minute or so.");
checkProcessExistence("MPlayer", true, null, configuration.getMplayerPath(), "dummy");
View
87 src/main/java/net/pms/configuration/PmsConfiguration.java
@@ -150,6 +150,8 @@
private static final String KEY_PLUGIN_DIRECTORY = "plugins";
private static final String KEY_PREVENTS_SLEEP = "prevents_sleep_mode";
private static final String KEY_PROFILE_NAME = "name";
+ private static final String KEY_RENDERER_DEFAULT = "renderer_default";
+ private static final String KEY_RENDERER_FORCE_DEFAULT = "renderer_force_default";
private static final String KEY_PROXY_SERVER_PORT = "proxy";
private static final String KEY_SERVER_HOSTNAME = "hostname";
private static final String KEY_SERVER_PORT = "port";
@@ -334,15 +336,37 @@ it is used as the profile directory and the profile is located there under the d
}
}
+ /**
+ * Default constructor that will attempt to load the PMS configuration file
+ * from the profile path.
+ *
+ * @throws ConfigurationException
+ * @throws IOException
+ */
public PmsConfiguration() throws ConfigurationException, IOException {
+ this(true);
+ }
+
+ /**
+ * Constructor that will initialize the PMS configuration.
+ *
+ * @param loadFile Set to true to attempt to load the PMS configuration
+ * file from the profile path. Set to false to skip
+ * loading.
+ * @throws ConfigurationException
+ * @throws IOException
+ */
+ public PmsConfiguration(boolean loadFile) throws ConfigurationException, IOException {
configuration = new PropertiesConfiguration();
configuration.setListDelimiter((char) 0);
configuration.setFileName(PROFILE_PATH);
- File pmsConfFile = new File(PROFILE_PATH);
-
- if (pmsConfFile.exists() && pmsConfFile.isFile()) {
- configuration.load(PROFILE_PATH);
+ if (loadFile) {
+ File pmsConfFile = new File(PROFILE_PATH);
+
+ if (pmsConfFile.exists() && pmsConfFile.isFile()) {
+ configuration.load(PROFILE_PATH);
+ }
}
tempFolder = new TempFolder(getString(KEY_TEMP_FOLDER_PATH, null));
@@ -2065,6 +2089,61 @@ public void setAudioResample(boolean value) {
configuration.setProperty(KEY_AUDIO_RESAMPLE, value);
}
+ /**
+ * Returns the name of the renderer to fall back on when header matching
+ * fails. PMS will recognize the configured renderer instead of "Unknown
+ * renderer". Default value is "", which means PMS will return the unknown
+ * renderer when no match can be made.
+ *
+ * @return The name of the renderer PMS should fall back on when header
+ * matching fails.
+ * @see #isRendererForceDefault()
+ */
+ public String getRendererDefault() {
+ return getString(KEY_RENDERER_DEFAULT, "");
+ }
+
+ /**
+ * Sets the name of the renderer to fall back on when header matching
+ * fails. PMS will recognize the configured renderer instead of "Unknow
+ * renderer". Set to "" to make PMS return the unknown renderer when no
+ * match can be made.
+ *
+ * @param value The name of the renderer to fall back on. This has to be
+ * <code>""</code> or a case insensitive match with the name
+ * used in any render configuration file.
+ * @see #setRendererForceDefault(boolean)
+ */
+ public void setRendererDefault(String value) {
+ configuration.setProperty(KEY_RENDERER_DEFAULT, value);
+ }
+
+ /**
+ * Returns true when PMS should not try to guess connecting renderers
+ * and instead force picking the defined fallback renderer. Default
+ * value is false, which means PMS will attempt to recognize connecting
+ * renderers by their headers.
+ *
+ * @return True when the fallback renderer should always be picked.
+ * @see #getRendererDefault()
+ */
+ public boolean isRendererForceDefault() {
+ return getBoolean(KEY_RENDERER_FORCE_DEFAULT, false);
+ }
+
+ /**
+ * Set to true when PMS should not try to guess connecting renderers
+ * and instead force picking the defined fallback renderer. Set to false
+ * to make PMS attempt to recognize connecting renderers by their headers.
+ *
+ * @param value Set to true when the fallback renderer should always be
+ * picked.
+ * @see #setRendererDefault(String)
+ */
+ public void setRendererForceDefault(boolean value) {
+ configuration.setProperty(KEY_RENDERER_FORCE_DEFAULT, value);
+ }
+
public String getVirtualFolders() {
return getString(KEY_VIRTUAL_FOLDERS, "");
}
View
63 src/main/java/net/pms/configuration/RendererConfiguration.java
@@ -33,6 +33,7 @@
*/
private static final Logger logger = LoggerFactory.getLogger(RendererConfiguration.class);
private static ArrayList<RendererConfiguration> renderersConfs;
+ private static PmsConfiguration pmsConfiguration;
private static RendererConfiguration defaultConf;
private static Map<InetAddress, RendererConfiguration> addressAssociation = new HashMap<InetAddress, RendererConfiguration>();
@@ -40,8 +41,15 @@ public static RendererConfiguration getDefaultConf() {
return defaultConf;
}
- public static void loadRendererConfigurations() {
+ /**
+ * Load all renderer configuration files and set up the default renderer.
+ *
+ * @param pmsConf
+ */
+ public static void loadRendererConfigurations(PmsConfiguration pmsConf) {
+ pmsConfiguration = pmsConf;
renderersConfs = new ArrayList<RendererConfiguration>();
+
try {
defaultConf = new RendererConfiguration();
} catch (ConfigurationException e) {
@@ -69,6 +77,29 @@ public static void loadRendererConfigurations() {
}
}
}
+
+ if (renderersConfs.size() > 0) {
+ // See if a different default configuration was configured
+ String rendererFallback = pmsConfiguration.getRendererDefault();
+
+ if (rendererFallback != null && !"".equals(rendererFallback)) {
+ RendererConfiguration fallbackConf = getRendererConfigurationByName(rendererFallback);
+
+ if (fallbackConf != null) {
+ // A valid fallback configuration was set, use it as default.
+ defaultConf = fallbackConf;
+ }
+ }
+ }
+ }
+
+ /**
+ * Returns the list of all renderer configurations.
+ *
+ * @return The list of all configurations.
+ */
+ public static ArrayList<RendererConfiguration> getAllRendererConfigurations() {
+ return renderersConfs;
}
protected static File getRenderersDir() {
@@ -127,9 +158,16 @@ public static RendererConfiguration getRendererConfigurationBySocketAddress(Inet
* @return The matching renderer configuration or <code>null</code>.
*/
public static RendererConfiguration getRendererConfigurationByUA(String userAgentString) {
- for (RendererConfiguration r : renderersConfs) {
- if (r.matchUserAgent(userAgentString)) {
- return manageRendererMatch(r);
+ if (pmsConfiguration.isRendererForceDefault()) {
+ // Force default renderer
+ logger.trace("Forcing renderer match to \"" + defaultConf.getRendererName() + "\"");
+ return manageRendererMatch(defaultConf);
+ } else {
+ // Try to find a match
+ for (RendererConfiguration r : renderersConfs) {
+ if (r.matchUserAgent(userAgentString)) {
+ return manageRendererMatch(r);
+ }
}
}
return null;
@@ -160,11 +198,18 @@ private static RendererConfiguration manageRendererMatch(RendererConfiguration r
* @return The matching renderer configuration or <code>null</code>.
*/
public static RendererConfiguration getRendererConfigurationByUAAHH(String header) {
- for (RendererConfiguration r : renderersConfs) {
- if (StringUtils.isNotBlank(r.getUserAgentAdditionalHttpHeader()) && header.startsWith(r.getUserAgentAdditionalHttpHeader())) {
- String value = header.substring(header.indexOf(":", r.getUserAgentAdditionalHttpHeader().length()) + 1);
- if (r.matchAdditionalUserAgent(value)) {
- return manageRendererMatch(r);
+ if (pmsConfiguration.isRendererForceDefault()) {
+ // Force default renderer
+ logger.trace("Forcing renderer match to \"" + defaultConf.getRendererName() + "\"");
+ return manageRendererMatch(defaultConf);
+ } else {
+ // Try to find a match
+ for (RendererConfiguration r : renderersConfs) {
+ if (StringUtils.isNotBlank(r.getUserAgentAdditionalHttpHeader()) && header.startsWith(r.getUserAgentAdditionalHttpHeader())) {
+ String value = header.substring(header.indexOf(":", r.getUserAgentAdditionalHttpHeader().length()) + 1);
+ if (r.matchAdditionalUserAgent(value)) {
+ return manageRendererMatch(r);
+ }
}
}
}
View
3  src/main/java/net/pms/messages.properties
@@ -192,6 +192,9 @@ NetworkTab.32=HTTP Engine V2
NetworkTab.33=Prevent OS from sleeping while streaming
NetworkTab.34=Plugins
NetworkTab.35=Maximum bandwidth in Mb/s (0 means no limit):
+NetworkTab.36=Default renderer when automatic detection fails:
+NetworkTab.37=Unknown renderer
+NetworkTab.38=Force default renderer (disable automatic detection)
PMS.0=No renderers were found
PMS.1=Audio
PMS.2=\#- Cache -\#
View
95 src/main/java/net/pms/newgui/GeneralTab.java
@@ -28,6 +28,7 @@
import java.awt.event.ItemListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
+import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
@@ -46,6 +47,7 @@
import net.pms.PMS;
import net.pms.configuration.Build;
import net.pms.configuration.PmsConfiguration;
+import net.pms.configuration.RendererConfiguration;
import net.pms.external.ExternalFactory;
import net.pms.external.ExternalListener;
import net.pms.network.NetworkConfiguration;
@@ -66,7 +68,7 @@
private static final Logger logger = LoggerFactory.getLogger(GeneralTab.class);
private static final String COL_SPEC = "left:pref, 2dlu, p, 2dlu , p, 2dlu, p, 2dlu, pref:grow";
- private static final String ROW_SPEC = "p, 0dlu, p, 0dlu, p, 3dlu, p, 3dlu, p, 3dlu,p, 3dlu, p, 15dlu, p, 3dlu,p, 3dlu, p, 3dlu, p, 3dlu, p, 3dlu, p, 3dlu, p,3dlu, p, 3dlu, p, 15dlu, p,3dlu, p, 3dlu, p, 15dlu, p, 3dlu, p";
+ private static final String ROW_SPEC = "p, 0dlu, p, 0dlu, p, 3dlu, p, 3dlu, p, 3dlu,p, 3dlu, p, 15dlu, p, 3dlu,p, 3dlu, p, 3dlu, p, 3dlu, p, 3dlu, p, 3dlu, p,3dlu, p, 3dlu, p, 15dlu, p,3dlu, p, 3dlu, p, 3dlu, p, 3dlu, p, 15dlu, p, 3dlu, p";
private JCheckBox smcheckBox;
private JCheckBox autoUpdateCheckBox;
@@ -78,6 +80,7 @@
private JComboBox networkinterfacesCBX;
private JTextField ip_filter;
private JTextField maxbitrate;
+ private JComboBox renderers;
private JPanel pPlugins;
private final PmsConfiguration configuration;
@@ -337,12 +340,57 @@ public void itemStateChanged(ItemEvent e) {
});
builder.add(preventSleep, FormLayoutUtil.flip(cc.xyw(1, 37, 9), colSpec, orientation));
- cmp = builder.addSeparator(Messages.getString("NetworkTab.34"), FormLayoutUtil.flip(cc.xyw(1, 39, 9), colSpec, orientation));
+ JCheckBox fdCheckBox = new JCheckBox(Messages.getString("NetworkTab.38"));
+ fdCheckBox.setContentAreaFilled(false);
+ fdCheckBox.addItemListener(new ItemListener() {
+ public void itemStateChanged(ItemEvent e) {
+ configuration.setRendererForceDefault((e.getStateChange() == ItemEvent.SELECTED));
+ }
+ });
+
+ if (configuration.isRendererForceDefault()) {
+ fdCheckBox.setSelected(true);
+ }
+
+ builder.addLabel(Messages.getString("NetworkTab.36"), FormLayoutUtil.flip(cc.xy(1, 39), colSpec, orientation));
+
+ ArrayList<RendererConfiguration> allConfs = RendererConfiguration.getAllRendererConfigurations();
+ ArrayList<Object> keyValues = new ArrayList<Object>();
+ ArrayList<Object> nameValues = new ArrayList<Object>();
+ keyValues.add("");
+ nameValues.add(Messages.getString("NetworkTab.37"));
+
+ if (allConfs != null) {
+ for (RendererConfiguration renderer : allConfs) {
+ if (renderer != null) {
+ keyValues.add(renderer.getRendererName());
+ nameValues.add(renderer.getRendererName());
+ }
+ }
+ }
+
+ final KeyedComboBoxModel renderersKcbm = new KeyedComboBoxModel(
+ (Object[]) keyValues.toArray(new Object[keyValues.size()]),
+ (Object[]) nameValues.toArray(new Object[nameValues.size()]));
+ renderers = new JComboBox(renderersKcbm);
+ renderers.setEditable(false);
+ String defaultRenderer = configuration.getRendererDefault();
+ renderersKcbm.setSelectedKey(defaultRenderer);
+
+ if (renderers.getSelectedIndex() == -1) {
+ renderers.setSelectedIndex(0);
+ }
+
+ builder.add(renderers, FormLayoutUtil.flip(cc.xyw(3, 39, 7), colSpec, orientation));
+
+ builder.add(fdCheckBox, FormLayoutUtil.flip(cc.xyw(1, 41, 9), colSpec, orientation));
+
+ cmp = builder.addSeparator(Messages.getString("NetworkTab.34"), FormLayoutUtil.flip(cc.xyw(1, 43, 9), colSpec, orientation));
cmp = (JComponent) cmp.getComponent(0);
cmp.setFont(cmp.getFont().deriveFont(Font.BOLD));
pPlugins = new JPanel(new GridLayout());
- builder.add(pPlugins, FormLayoutUtil.flip(cc.xyw(1, 41, 9), colSpec, orientation));
+ builder.add(pPlugins, FormLayoutUtil.flip(cc.xyw(1, 45, 9), colSpec, orientation));
JPanel panel = builder.getPanel();
@@ -366,6 +414,47 @@ private KeyedComboBoxModel createNetworkInterfacesModel() {
return networkInterfaces;
}
+ /**
+ * Add the renderer configuration selection after they have been intialized.
+ */
+ public void addRenderers() {
+ ArrayList<RendererConfiguration> allConfs = RendererConfiguration.getAllRendererConfigurations();
+ ArrayList<Object> keyValues = new ArrayList<Object>();
+ ArrayList<Object> nameValues = new ArrayList<Object>();
+ keyValues.add("");
+ nameValues.add(Messages.getString("NetworkTab.37"));
+
+ if (allConfs != null) {
+ for (RendererConfiguration renderer : allConfs) {
+ if (renderer != null) {
+ keyValues.add(renderer.getRendererName());
+ nameValues.add(renderer.getRendererName());
+ }
+ }
+ }
+
+ final KeyedComboBoxModel renderersKcbm = new KeyedComboBoxModel(
+ (Object[]) keyValues.toArray(new Object[keyValues.size()]),
+ (Object[]) nameValues.toArray(new Object[nameValues.size()]));
+ renderers.setModel(renderersKcbm);
+ renderers.setEditable(false);
+ String defaultRenderer = configuration.getRendererDefault();
+ renderersKcbm.setSelectedKey(defaultRenderer);
+
+ if (renderers.getSelectedIndex() == -1) {
+ renderers.setSelectedIndex(0);
+ }
+
+ renderers.addItemListener(new ItemListener() {
+ public void itemStateChanged(ItemEvent e) {
+ if (e.getStateChange() == ItemEvent.SELECTED) {
+ logger.info("Setting renderer default: \"" + renderersKcbm.getSelectedKey() + "\"");
+ configuration.setRendererDefault((String) renderersKcbm.getSelectedKey());
+ }
+ }
+ });
+ }
+
public void addPlugins() {
FormLayout layout = new FormLayout(
"fill:10:grow",
View
1  src/main/java/net/pms/newgui/LooksFrame.java
@@ -492,6 +492,7 @@ public void addRendererIcon(int code, String msg, String icon) {
@Override
public void serverReady() {
+ nt.addRenderers();
nt.addPlugins();
}
View
136 src/test/java/net/pms/test/RendererConfigurationTest.java
@@ -22,14 +22,17 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
+import java.io.IOException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
+import net.pms.configuration.PmsConfiguration;
import net.pms.configuration.RendererConfiguration;
+import org.apache.commons.configuration.ConfigurationException;
import org.junit.Before;
import org.junit.Test;
import org.slf4j.LoggerFactory;
@@ -43,8 +46,8 @@
public class RendererConfigurationTest {
private final Map<String, String> testCases = new HashMap<String, String>();
- @Before
- public void setUp() {
+ @Before
+ public void setUp() {
// Silence all log messages from the PMS code that is being tested
LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
context.reset();
@@ -52,6 +55,7 @@ public void setUp() {
// Cases that are too generic should not match anything
testCases.put("User-Agent: UPnP/1.0 DLNADOC/1.50", null);
testCases.put("User-Agent: Unknown Renderer", null);
+ testCases.put("X-Unknown-Header: Unknown Content", null);
// From AirPlayer.conf:
testCases.put("User-Agent: AirPlayer/1.0.09 CFNetwork/485.13.9 Darwin/11.0.0", "AirPlayer");
@@ -96,36 +100,104 @@ public void setUp() {
// From XBMC.conf:
testCases.put("User-Agent: XBMC/10.0 r35648 (Mac OS X; 11.2.0 x86_64; http://www.xbmc.org)", "XBMC");
testCases.put("User-Agent: Platinum/0.5.3.0, DLNADOC/1.50", "XBMC");
-
- // Initialize the RendererConfiguration
- RendererConfiguration.loadRendererConfigurations();
}
- /**
- * Test the RendererConfiguration class and the consistency of the
- * renderer .conf files it reads. This is done by feeding it known
- * headers and checking whether it recognizes the correct renderer.
- */
- @Test
- public void testKnownHeaders() {
- // Test all header test cases
- Set<Entry<String, String>> set = testCases.entrySet();
- Iterator<Entry<String, String>> i = set.iterator();
-
- while (i.hasNext()) {
- Entry<String, String> entry = (Entry<String, String>) i.next();
- testHeader(entry.getKey(), entry.getValue());
- }
- }
-
- /**
- * Test one particular header line to see if it returns the correct
- * renderer. Set the correct renderer name to <code>null</code> to
- * require that nothing matches at all.
- *
- * @param headerLine The header line to recognize.
- * @param correctRendererName The name of the renderer.
- */
+ /**
+ * Test the RendererConfiguration class and the consistency of the renderer
+ * .conf files it reads. This is done by feeding it known headers and
+ * checking whether it recognizes the correct renderer.
+ */
+ @Test
+ public void testKnownHeaders() {
+ PmsConfiguration pmsConf = null;
+
+ try {
+ pmsConf = new PmsConfiguration(false);
+ } catch (IOException e) {
+ // This should be impossible since no configuration file will be loaded.
+ } catch (ConfigurationException e) {
+ // This should be impossible since no configuration file will be loaded.
+ }
+
+ // Initialize the RendererConfiguration
+ RendererConfiguration.loadRendererConfigurations(pmsConf);
+
+ // Test all header test cases
+ Set<Entry<String, String>> set = testCases.entrySet();
+ Iterator<Entry<String, String>> i = set.iterator();
+
+ while (i.hasNext()) {
+ Entry<String, String> entry = (Entry<String, String>) i.next();
+ testHeader(entry.getKey(), entry.getValue());
+ }
+ }
+
+ /**
+ * Test recognition with a forced default renderer configured.
+ */
+ @Test
+ public void testForcedDefault() {
+ PmsConfiguration pmsConf = null;
+
+ try {
+ pmsConf = new PmsConfiguration(false);
+ } catch (IOException e) {
+ // This should be impossible since no configuration file will be loaded.
+ } catch (ConfigurationException e) {
+ // This should be impossible since no configuration file will be loaded.
+ }
+
+ // Set default to Playstation 3
+ pmsConf.setRendererDefault("Playstation 3");
+ pmsConf.setRendererForceDefault(true);
+
+ // Initialize the RendererConfiguration
+ RendererConfiguration.loadRendererConfigurations(pmsConf);
+
+ // Known and unknown renderers should always return default
+ testHeader("User-Agent: AirPlayer/1.0.09 CFNetwork/485.13.9 Darwin/11.0.0", "Playstation 3");
+ testHeader("User-Agent: Unknown Renderer", "Playstation 3");
+ testHeader("X-Unknown-Header: Unknown Content", "Playstation 3");
+ }
+
+ /**
+ * Test recognition with a forced bogus default renderer configured.
+ */
+ @Test
+ public void testBogusDefault() {
+ PmsConfiguration pmsConf = null;
+
+ try {
+ pmsConf = new PmsConfiguration(false);
+ } catch (IOException e) {
+ // This should be impossible since no configuration file will be loaded.
+ } catch (ConfigurationException e) {
+ // This should be impossible since no configuration file will be loaded.
+ }
+
+ // Set default to non existent renderer
+ pmsConf.setRendererDefault("Bogus Renderer");
+ pmsConf.setRendererForceDefault(true);
+
+ // Initialize the RendererConfiguration
+ RendererConfiguration.loadRendererConfigurations(pmsConf);
+
+ // Known and unknown renderers should return "Unknown renderer"
+ testHeader("User-Agent: AirPlayer/1.0.09 CFNetwork/485.13.9 Darwin/11.0.0", "Unknown renderer");
+ testHeader("User-Agent: Unknown Renderer", "Unknown renderer");
+ testHeader("X-Unknown-Header: Unknown Content", "Unknown renderer");
+ }
+
+ /**
+ * Test one particular header line to see if it returns the correct
+ * renderer. Set the correct renderer name to <code>null</code> to require
+ * that nothing matches at all.
+ *
+ * @param headerLine
+ * The header line to recognize.
+ * @param correctRendererName
+ * The name of the renderer.
+ */
private void testHeader(String headerLine, String correctRendererName) {
if (correctRendererName != null) {
// Header is supposed to match a particular renderer
@@ -157,8 +229,8 @@ private void testHeader(String headerLine, String correctRendererName) {
// Match by additional header
RendererConfiguration rc = RendererConfiguration.getRendererConfigurationByUAAHH(headerLine);
assertEquals("Expected no matching renderer to be found for header \"" + headerLine
- + "\", instead renderer \"" + rc.getRendererName() + "\" was recognized.", null,
- rc);
+ + "\", instead renderer \"" + (rc != null ? rc.getRendererName() : "")
+ + "\" was recognized.", null, rc);
}
}
}
View
12 src/test/java/net/pms/test/formats/FormatRecognitionTest.java
@@ -69,8 +69,18 @@ public void setUp() {
LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
context.reset();
+ PmsConfiguration pmsConf = null;
+
+ try {
+ pmsConf = new PmsConfiguration(false);
+ } catch (IOException e) {
+ // This should be impossible since no configuration file will be loaded.
+ } catch (ConfigurationException e) {
+ // This should be impossible since no configuration file will be loaded.
+ }
+
// Initialize the RendererConfiguration
- RendererConfiguration.loadRendererConfigurations();
+ RendererConfiguration.loadRendererConfigurations(pmsConf);
mediaInfoParserIsValid = MediaInfoParser.isValid();
}
Please sign in to comment.
Something went wrong with that request. Please try again.