2020-09-19 14:33:40 -04:00
|
|
|
package d2records
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
refactored logging in d2loader, d2record, and d2asset (#898)
* refactored logging in d2config, d2record, and d2asset
* asset manager, record manager, and file loader now utilitize d2util.Logger
* added colored logging to d2util.Logger (excluding windows platforms)
* removed mpq file verification from d2config; d2loader handles this
* record loaders now use the record manager's logger for printing info
* added command line argument for setting log level (`--loglevel 4`, `-l4`, or `-l 4`
* added `LogLevel` parameter to config file
* default log level will show errors, warnings, and info log messages
* specifying log level as an argument overrides setting from config file
* fixed log level tests
2020-11-02 21:23:07 -05:00
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2util"
|
|
|
|
|
2020-09-19 14:33:40 -04:00
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum"
|
|
|
|
|
|
|
|
testify "github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Verify the lookup returns the right object after indexing.
|
|
|
|
func TestIndexObjects(t *testing.T) {
|
|
|
|
assert := testify.New(t)
|
|
|
|
|
refactored logging in d2loader, d2record, and d2asset (#898)
* refactored logging in d2config, d2record, and d2asset
* asset manager, record manager, and file loader now utilitize d2util.Logger
* added colored logging to d2util.Logger (excluding windows platforms)
* removed mpq file verification from d2config; d2loader handles this
* record loaders now use the record manager's logger for printing info
* added command line argument for setting log level (`--loglevel 4`, `-l4`, or `-l 4`
* added `LogLevel` parameter to config file
* default log level will show errors, warnings, and info log messages
* specifying log level as an argument overrides setting from config file
* fixed log level tests
2020-11-02 21:23:07 -05:00
|
|
|
r, err := NewRecordManager(d2util.LogLevelDefault)
|
2020-09-23 13:30:54 -04:00
|
|
|
if err != nil {
|
2020-11-21 05:33:22 -05:00
|
|
|
t.Error(err)
|
2020-09-23 13:30:54 -04:00
|
|
|
}
|
2020-09-19 14:33:40 -04:00
|
|
|
|
|
|
|
testObjects := []ObjectLookupRecord{
|
|
|
|
{Act: 1, Type: d2enum.ObjectTypeCharacter, Id: 0, Description: "Act1CharId0"},
|
|
|
|
{Act: 1, Type: d2enum.ObjectTypeCharacter, Id: 1, Description: "Act1CharId1"},
|
|
|
|
{Act: 1, Type: d2enum.ObjectTypeCharacter, Id: 2, Description: "Act1CharId2"},
|
|
|
|
{Act: 1, Type: d2enum.ObjectTypeCharacter, Id: 3, Description: "Act1CharId3"},
|
|
|
|
{Act: 1, Type: d2enum.ObjectTypeItem, Id: 0, Description: "Act1ItemId0"},
|
|
|
|
{Act: 1, Type: d2enum.ObjectTypeItem, Id: 1, Description: "Act1ItemId1"},
|
|
|
|
{Act: 1, Type: d2enum.ObjectTypeItem, Id: 2, Description: "Act1ItemId2"},
|
|
|
|
{Act: 1, Type: d2enum.ObjectTypeItem, Id: 3, Description: "Act1ItemId3"},
|
|
|
|
{Act: 2, Type: d2enum.ObjectTypeCharacter, Id: 0, Description: "Act2CharId0"},
|
|
|
|
{Act: 2, Type: d2enum.ObjectTypeCharacter, Id: 1, Description: "Act2CharId1"},
|
|
|
|
{Act: 2, Type: d2enum.ObjectTypeCharacter, Id: 2, Description: "Act2CharId2"},
|
|
|
|
{Act: 2, Type: d2enum.ObjectTypeCharacter, Id: 3, Description: "Act2CharId3"},
|
|
|
|
{Act: 2, Type: d2enum.ObjectTypeItem, Id: 0, Description: "Act2ItemId0"},
|
|
|
|
{Act: 2, Type: d2enum.ObjectTypeItem, Id: 1, Description: "Act2ItemId1"},
|
|
|
|
{Act: 2, Type: d2enum.ObjectTypeItem, Id: 2, Description: "Act2ItemId2"},
|
|
|
|
{Act: 2, Type: d2enum.ObjectTypeItem, Id: 3, Description: "Act2ItemId3"},
|
|
|
|
}
|
|
|
|
|
|
|
|
r.initObjectRecords(testObjects)
|
|
|
|
|
|
|
|
typeCharacter := int(d2enum.ObjectTypeCharacter)
|
|
|
|
typeItem := int(d2enum.ObjectTypeItem)
|
|
|
|
|
|
|
|
assert.Equal("Act1CharId2", r.lookupObject(1, typeCharacter, 2).Description)
|
|
|
|
assert.Equal("Act1ItemId0", r.lookupObject(1, typeItem, 0).Description)
|
|
|
|
assert.Equal("Act2CharId3", r.lookupObject(2, typeCharacter, 3).Description)
|
|
|
|
assert.Equal("Act2ItemId1", r.lookupObject(2, typeItem, 1).Description)
|
|
|
|
}
|