VASSAL.tools.lang.MemoryUtilsTest.java Source code

Java tutorial

Introduction

Here is the source code for VASSAL.tools.lang.MemoryUtilsTest.java

Source

/*
 * $Id$
 *
 * Copyright (c) 2007 by Joel Uckelman
 * Copyright (c) 2013 by Marc Pawlowsky
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License (LGPL) as published by the Free Software Foundation.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, copies are available
 * at http://www.opensource.org.
 */

package VASSAL.tools.lang;

import static org.junit.Assert.assertEquals;
import static org.junit.Assume.assumeTrue;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

import org.apache.commons.lang.SystemUtils;
import org.junit.Ignore;
import org.junit.Test;

public class MemoryUtilsTest {
    @Test
    public void testGetPhysicalMemoryUNIX() throws IOException {
        assumeTrue(SystemUtils.IS_OS_UNIX && !SystemUtils.IS_OS_MAC_OSX);

        // get the total RAM from the system, in kB
        final Process p = Runtime.getRuntime()
                .exec(new String[] { "sh", "-c", "grep '^MemTotal:' /proc/meminfo | sed 's/[^0-9]//g'" });

        final BufferedReader r = new BufferedReader(new InputStreamReader(p.getInputStream()));

        final int eRAM = Integer.parseInt(r.readLine());
        r.close();

        // check that it's correct
        assertEquals(eRAM, MemoryUtils.getPhysicalMemory() >> 10);
    }

    // FIXME: how to get RAM on Mac OS X?
    @Ignore
    @Test
    public void testGetPhysicalMemoryMacOSX() {
        assumeTrue(SystemUtils.IS_OS_MAC_OSX);
    }

    // FIXME: how to get RAM on Windows?
    @Ignore
    @Test
    public void testGetPhysicalMemoryWindows() {
        assumeTrue(SystemUtils.IS_OS_WINDOWS);
    }
}