Exemplo n.º 1
0
func (*GrubTester) TestSetup(c *C.C) {
	wantSettingsContent := `GRUB_BACKGROUND="<none>"
GRUB_CMDLINE_LINUX="locale=zh_CN.UTF-8 url=http://cdimage/nfsroot/deepin-2014/desktop/current/amd64/preseed/deepin.seed initrd=http://cdimage/nfsroot/deepin-2014/desktop/current/amd64/casper/initrd.lz"
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"
GRUB_DEFAULT="0"
GRUB_DISTRIBUTOR="` + "`lsb_release -d -s 2> /dev/null || echo Debian`" + `"
GRUB_GFXMODE="1200x900"
GRUB_THEME="/tmp/dde_daemon_grub2_test/dde_daemon_grub2_test_theme_dir/theme.txt"
GRUB_TIMEOUT="5"
`

	// prepare
	configFile = tmpBaseDir + "/grub2.json"
	utils.EnsureDirExist(tmpThemeDir)
	utils.CopyFile(testGrubThemeBackgroundSourceFile, tmpThemeDir+"/background_source")
	SetDefaultGrubSettingFile(tmpConfigFile)
	SetDefaultThemeDir(tmpThemeDir)
	defer func() {
		configFile = ConfigFileDefault
		SetDefaultGrubSettingFile(DefaultGrubSettingFile)
		SetDefaultThemeDir(DefaultThemeDir)
	}()

	g := NewGrub2()
	var w, h int

	// setup with target gfxmode
	utils.CopyFile(testGrubSettingsFile, tmpConfigFile)
	g.Setup(tmpGfxmode)
	settingContentBuf, _ := ioutil.ReadFile(tmpConfigFile)
	c.Check(string(settingContentBuf), C.Equals, wantSettingsContent)
	g.readSettings()
	c.Check(g.getSettingDefaultEntry(), C.Equals, "0")
	c.Check(g.getSettingTimeout(), C.Equals, int32(5))
	c.Check(g.getSettingGfxmode(), C.Equals, tmpGfxmode)
	c.Check(g.getSettingTheme(), C.Equals, tmpThemeDir+"/theme.txt")
	w, h, _ = graphic.GetImageSize(tmpThemeDir + "/background.png")
	c.Check(w, C.Equals, 1200)
	c.Check(h, C.Equals, 900)
}
Exemplo n.º 2
0
func (*GrubTester) TestSetupGfxmode(c *C.C) {
	// prepare
	configFile = tmpBaseDir + "/grub2.json"
	utils.EnsureDirExist(tmpThemeDir)
	utils.CopyFile(testGrubThemeBackgroundSourceFile, tmpThemeDir+"/background_source")
	SetDefaultGrubSettingFile(tmpConfigFile)
	SetDefaultThemeDir(tmpThemeDir)
	defer func() {
		configFile = ConfigFileDefault
		SetDefaultGrubSettingFile(DefaultGrubSettingFile)
		SetDefaultThemeDir(DefaultThemeDir)
	}()

	g := NewGrub2()
	var w, h int
	var sw, sh int
	tmpsw, tmpsh := getPrimaryScreenBestResolution()
	sw, sh = int(tmpsw), int(tmpsh)

	// setup with none gfxmode
	utils.CopyFile(testGrubSettingsFile, tmpConfigFile)
	g.Setup("")
	g.readSettings()
	c.Check(g.getSettingDefaultEntry(), C.Equals, "0")
	c.Check(g.getSettingTimeout(), C.Equals, int32(5))
	c.Check(g.getSettingGfxmode(), C.Equals, getDefaultGfxmode())
	c.Check(g.getSettingTheme(), C.Equals, tmpThemeDir+"/theme.txt")
	w, h, _ = graphic.GetImageSize(tmpThemeDir + "/background.png")
	c.Check(w, C.Equals, sw)
	c.Check(h, C.Equals, sh)

	// setup with none gfxmode
	utils.CopyFile(testGrubSettingsFile, tmpConfigFile)
	g.Setup("auto")
	g.readSettings()
	c.Check(g.getSettingDefaultEntry(), C.Equals, "0")
	c.Check(g.getSettingTimeout(), C.Equals, int32(5))
	c.Check(g.getSettingGfxmode(), C.Equals, "auto")
	c.Check(g.getSettingTheme(), C.Equals, tmpThemeDir+"/theme.txt")
	w, h, _ = graphic.GetImageSize(tmpThemeDir + "/background.png")
	c.Check(w, C.Equals, sw)
	c.Check(h, C.Equals, sh)

	// setup with wrong gfxmode format

	// will following error message in this case, so we just disable
	// all output and recovery it when done
	oldLogLevel := logger.GetLogLevel()
	logger.SetLogLevel(log.LevelDisable)
	defer logger.SetLogLevel(oldLogLevel)

	utils.CopyFile(testGrubSettingsFile, tmpConfigFile)
	g.Setup("1024x")
	g.readSettings()
	c.Check(g.getSettingDefaultEntry(), C.Equals, "0")
	c.Check(g.getSettingTimeout(), C.Equals, int32(5))
	c.Check(g.getSettingGfxmode(), C.Equals, "1024x")
	c.Check(g.getSettingTheme(), C.Equals, tmpThemeDir+"/theme.txt")
	w, h, _ = graphic.GetImageSize(tmpThemeDir + "/background.png")
	c.Check(w, C.Equals, sw)
	c.Check(h, C.Equals, sh)
}