Пример #1
0
func TestParseDat(t *testing.T) {
	dat, _, err := ParseDat(strings.NewReader(datText), "testing/dat")

	if err != nil {
		t.Fatalf("error parsing test data: %v", err)
	}

	datGolden := &types.Dat{
		Name:        "Acorn Archimedes - Applications",
		Description: "Acorn Archimedes - Applications (TOSEC-v2008-10-11)",
		Games: []*types.Game{
			&types.Game{
				Name:        "Acorn Archimedes RISC OS Application Suite v1.00 (19xx)(Acorn)(Disk 1 of 2)[a][Req RISC OS]",
				Description: "Acorn Archimedes RISC OS Application Suite v1.00 (19xx)(Acorn)(Disk 1 of 2)[a][Req RISC OS]",
				Roms: []*types.Rom{
					&types.Rom{
						Name: "Acorn Archimedes RISC OS Application Suite v1.00 (19xx)(Acorn)(Disk 1 of 2)[a][Req RISC OS].adf",
						Size: 819200,
						Crc:  []byte{0xe4, 0x31, 0x66, 0xb9},
						Md5:  []byte{0x43, 0xee, 0x6a, 0xcc, 0xc, 0x17, 0x30, 0x48, 0xf4, 0x78, 0x26, 0x30, 0x7c, 0xa, 0x26, 0x2e},
					},
				},
			},
			&types.Game{
				Name:        "Afterburner (1989)(Sega)(Side A)[cr NEC]",
				Description: "Afterburner (1989)(Sega)(Side A)[cr NEC]",
				Roms: []*types.Rom{
					&types.Rom{
						Name: "Afterburner (1989)(Sega)(Side A)[cr NEC].g64",
						Size: 333744,
						Crc:  []byte{0x17, 0x5a, 0x3f, 0x26},
						Md5:  []byte{0x36, 0xec, 0xf1, 0x37, 0x1d, 0x33, 0x91, 0xc0, 0x6c, 0x16, 0xf7, 0x51, 0x43, 0x1c, 0x93, 0x2b},
						Sha1: []byte{0x80, 0x35, 0x3c, 0xb1, 0x68, 0xdc, 0x5d, 0x7c, 0xc1, 0xdc, 0xe5, 0x79, 0x71, 0xf4, 0xea, 0x26, 0x40, 0xa5, 0xa, 0xc4},
					},
				},
			},
		},
	}

	datGolden.Normalize()

	if !datGolden.Equals(dat) {
		fmt.Printf("datGolden=%s\n", string(types.PrintDat(datGolden)))
		fmt.Printf("dat=%s\n", string(types.PrintDat(dat)))
		t.Fatalf("parsed dat differs from golden dat")
	}
}
Пример #2
0
func TestParserXmlGoesThrough(t *testing.T) {
	dat, _, err := Parse("testdata/example.xml")
	if err != nil {
		t.Fatalf("error parsing test data: %v", err)
	}

	fmt.Printf("dat: %s\n", string(types.PrintDat(dat)))
}
Пример #3
0
func TestParseForceZipXml(t *testing.T) {
	dat, _, err := ParseXml(strings.NewReader(xmlForceZipText), "testing/xml")

	if err != nil {
		t.Fatalf("error parsing test data: %v", err)
	}

	datGolden := &types.Dat{
		Name:        "AgeMame Artwork",
		Description: "AgeMame Artwork",
		UnzipGames:  true,
	}

	datGolden.Normalize()

	if !datGolden.Equals(dat) {
		fmt.Printf("datGolden=%s\n", string(types.PrintDat(datGolden)))
		fmt.Printf("dat=%s\n", string(types.PrintDat(dat)))
		t.Fatalf("parsed dat differs from golden dat")
	}
}
Пример #4
0
func TestParseForceZipDat(t *testing.T) {
	dat, _, err := ParseDat(strings.NewReader(datForceZipText), "testing/dat")

	if err != nil {
		t.Fatalf("error parsing test data: %v", err)
	}

	datGolden := &types.Dat{
		Name:        "Acorn Archimedes - Applications",
		Description: "Acorn Archimedes - Applications (TOSEC-v2008-10-11)",
		UnzipGames:  true,
	}

	datGolden.Normalize()

	if !datGolden.Equals(dat) {
		fmt.Printf("datGolden=%s\n", string(types.PrintDat(datGolden)))
		fmt.Printf("dat=%s\n", string(types.PrintDat(dat)))
		t.Fatalf("parsed dat differs from golden dat")
	}
}
Пример #5
0
func lookupByHash(hash []byte) (bool, error) {
	found := false
	if len(hash) == sha1.Size {
		dat, err := romDB.GetDat(hash)
		if err != nil {
			return false, err
		}

		if dat != nil {
			fmt.Printf("dat = %s\n", types.PrintDat(dat))
			found = true
		}
	}

	r := new(types.Rom)
	switch len(hash) {
	case md5.Size:
		r.Md5 = hash
	case crc32.Size:
		r.Crc = hash
	case sha1.Size:
		r.Sha1 = hash
	default:
		return false, fmt.Errorf("found unknown hash size: %d", len(hash))
	}

	dats, err := romDB.DatsForRom(r)
	if err != nil {
		return false, err
	}

	for _, dat := range dats {
		fmt.Printf("dat = %s\n", types.PrintDat(dat))
	}

	found = found || len(dats) > 0
	return found, nil
}
Пример #6
0
func (rs *RombaService) lookupRom(cmd *commander.Command, r *types.Rom, outpath string) error {
	err := rs.romDB.CompleteRom(r)
	if err != nil {
		return err
	}

	if r.Sha1 != nil {
		sha1Str := hex.EncodeToString(r.Sha1)

		inDepot, hh, rompath, size, err := rs.depot.SHA1InDepot(sha1Str)
		if err != nil {
			return err
		}

		if inDepot {
			fmt.Fprintf(cmd.Stdout, "-----------------\n")
			fmt.Fprintf(cmd.Stdout, "rom file %s in depot\n", rompath)
			fmt.Fprintf(cmd.Stdout, "crc = %s\n", hex.EncodeToString(hh.Crc))
			fmt.Fprintf(cmd.Stdout, "md5 = %s\n", hex.EncodeToString(hh.Md5))
			fmt.Fprintf(cmd.Stdout, "size = %d\n", size)
			r.Crc = hh.Crc
			r.Md5 = hh.Md5

			if outpath != "" {
				worker.Cp(rompath, filepath.Join(outpath, filepath.Base(rompath)))
			}
		}
	}

	dats, err := rs.romDB.DatsForRom(r)
	if err != nil {
		return err
	}

	if len(dats) > 0 {
		fmt.Fprintf(cmd.Stdout, "-----------------\n")
		fmt.Fprintf(cmd.Stdout, "rom found in:\n")
		for _, dat := range dats {
			dn := dat.NarrowToRom(r)
			if dn != nil {
				fmt.Fprintf(cmd.Stdout, "%s\n", types.PrintDat(dn))
			}
		}
	}
	return nil
}
Пример #7
0
func TestParseXml(t *testing.T) {
	dat, _, err := ParseXml(strings.NewReader(xmlText), "testing/xml")

	if err != nil {
		t.Fatalf("error parsing test data: %v", err)
	}

	datGolden := &types.Dat{
		Name:        "AgeMame Artwork",
		Description: "AgeMame Artwork",
		Games: []*types.Game{
			&types.Game{
				Name:        "bfmdrwho",
				Description: "bfmdrwho",
				Roms: []*types.Rom{
					&types.Rom{
						Name: "alloff.png",
						Size: 398080,
						Crc:  []byte{0x4a, 0xe0, 0x27, 0x49},
						Md5:  []byte{0xce, 0x23, 0x4f, 0x1, 0xd8, 0x6, 0x8a, 0xaa, 0xb7, 0x7, 0x5c, 0x3a, 0x42, 0xfe, 0x52, 0x3d},
						Sha1: []byte{0xf6, 0x38, 0x9b, 0x4a, 0xfc, 0x93, 0x2a, 0xe4, 0x2, 0x2, 0xc5, 0x75, 0xa6, 0xc5, 0xba, 0x25, 0xde, 0xaa, 0xee, 0xf4},
					},
					&types.Rom{
						Name: "bfmdrwho.lay",
						Size: 66185,
						Crc:  []byte{0x90, 0xb9, 0x8b, 0x40},
						Md5:  []byte{0xc, 0x92, 0xbd, 0x59, 0xc8, 0x4, 0xd4, 0xe3, 0x51, 0x70, 0x20, 0x82, 0x5, 0x16, 0x65, 0x76},
						Sha1: []byte{0xff, 0xc, 0xe, 0x7d, 0xed, 0xea, 0xf8, 0x46, 0x1e, 0x11, 0x50, 0x62, 0x9, 0x2a, 0x10, 0x6a, 0xa0, 0xd5, 0x84, 0x52},
					},
				},
			},
			&types.Game{
				Name:        "megaman7p",
				Description: "Mega Man 7 (USA, Final Prototype)",
				Roms: []*types.Rom{
					&types.Rom{
						Name: "rom 0.u1",
						Size: 524288,
						Crc:  []byte{0x87, 0x42, 0xaa, 0x77},
						Sha1: []byte{0x60, 0xe7, 0xa8, 0x36, 0x20, 0xef, 0xac, 0xfe, 0xf9, 0x82, 0x1f, 0x13, 0xc8, 0x36, 0x79, 0xfa, 0x24, 0x13, 0xfd, 0xd2},
					},
					&types.Rom{
						Name: "rom 1.u2",
						Size: 524288,
						Crc:  []byte{0x25, 0xee, 0xc9, 0xa},
						Sha1: []byte{0x2b, 0xed, 0xac, 0x3c, 0x3d, 0xde, 0x67, 0x80, 0x38, 0x9a, 0x98, 0x75, 0xa, 0xc0, 0x5c, 0xa1, 0xee, 0x41, 0xca, 0xf5},
					},
				},
			},
			&types.Game{
				Name:        "10yard",
				Description: "10-Yard Fight (World, set 1)",
				Roms: []*types.Rom{
					&types.Rom{
						Name: "yf-s.3b",
						Size: 8192,
						Crc:  []byte{0x3, 0x92, 0xa6, 0xc},
						Sha1: []byte{0x68, 0x3, 0x5, 0x4, 0xea, 0xfc, 0x58, 0xdb, 0x25, 0x0, 0x99, 0xed, 0xd3, 0xc3, 0x32, 0x3b, 0xdb, 0x9e, 0xff, 0x6b},
					},
					&types.Rom{
						Name: "yf-s.1b",
						Size: 8192,
						Crc:  []byte{0x65, 0x88, 0xf4, 0x1a},
						Sha1: []byte{0x20, 0x93, 0x5, 0xef, 0xc6, 0x81, 0x71, 0x88, 0x64, 0x27, 0x21, 0x6b, 0x9a, 0xb, 0x37, 0x33, 0x3f, 0x40, 0xda, 0xa8},
					},
					&types.Rom{
						Name: "41_9.12b",
						Size: 65536,
						Crc:  []byte{0xf, 0x9d, 0x85, 0x27},
					},
				},
			},
			&types.Game{
				Name:        "Games - Prototype (US)\\A.E. (US) [-] [N.A.]",
				Description: "A.E. (US) [-] [N.A.]",
				Roms: []*types.Rom{
					&types.Rom{
						Name: "Media\\A.E. (1982)(Atari)(proto).bin",
						Size: 16384,
						Crc:  []byte{0x35, 0x48, 0x47, 0x51},
						Md5:  []byte{0xa4, 0x7f, 0xcb, 0x4e, 0xed, 0xab, 0x94, 0x18, 0xea, 0x9, 0x8b, 0xb4, 0x31, 0xa4, 0x7, 0xaa},
					},
				},
			},
		},
	}

	datGolden.Normalize()

	if !datGolden.Equals(dat) {
		fmt.Printf("datGolden=%s\n", string(types.PrintDat(datGolden)))
		fmt.Printf("dat=%s\n", string(types.PrintDat(dat)))
		t.Fatalf("parsed dat differs from golden dat")
	}
}
Пример #8
0
func TestDB(t *testing.T) {
	dbDir, err := ioutil.TempDir("", "rombadb")
	if err != nil {
		t.Fatalf("cannot create temp dir for test db: %v", err)
	}

	t.Logf("creating test db in %s\n", dbDir)

	krdb, err := db.New(dbDir)
	if err != nil {
		t.Fatalf("failed to open db: %v", err)
	}

	dat, sha1Bytes, err := parser.ParseDat(strings.NewReader(datText), "testing/dat")
	if err != nil {
		t.Fatalf("failed to parse test dat: %v", err)
	}

	err = krdb.IndexDat(dat, sha1Bytes)
	if err != nil {
		t.Fatalf("failed to index test dat: %v", err)
	}

	datFromDb, err := krdb.GetDat(sha1Bytes)
	if err != nil {
		t.Fatalf("failed to retrieve test dat: %v", err)
	}

	if !datFromDb.Equals(dat) {
		fmt.Printf("datFromDb=%s\n", string(types.PrintDat(datFromDb)))
		fmt.Printf("dat=%s\n", string(types.PrintDat(dat)))
		t.Fatalf("dat differs from db dat")
	}

	romSha1Bytes, err := hex.DecodeString("80353cb168dc5d7cc1dce57971f4ea2640a50ac4")
	if err != nil {
		t.Fatalf("failed to hex decode: %v", err)
	}

	rom := new(types.Rom)
	rom.Sha1 = romSha1Bytes

	dats, err := krdb.DatsForRom(rom)
	if err != nil {
		t.Fatalf("failed to retrieve dats for rom: %v", err)
	}

	if len(dats) != 1 {
		t.Fatalf("couldn't find dats for rom")
	}

	datFromDb = dats[0]

	if !datFromDb.Equals(dat) {
		fmt.Printf("datFromDb=%s\n", string(types.PrintDat(datFromDb)))
		fmt.Printf("dat=%s\n", string(types.PrintDat(dat)))
		t.Fatalf("dat differs from db dat")
	}

	err = krdb.Close()
	if err != nil {
		t.Fatalf("failed to close db: %v", err)
	}

	err = os.RemoveAll(dbDir)
	if err != nil {
		t.Fatalf("failed to remove test db dir %s: %v", dbDir, err)
	}
}