How to use Logf method of log Package

Best Syzkaller code snippet using log.Logf

sonos_test.go

Source:sonos_test.go Github

copy

Full Screen

...87 s := getTestSonos(sonos.SVC_ALARM_CLOCK)88 if currentTimeFormat, currentDateFormat, err := s.GetFormat(); nil != err {89 t.Fatal(err)90 } else {91 t.Logf("GetFormat() -> \"%s\",\"%s\"", currentTimeFormat, currentDateFormat)92 }93 if index, autoAdjustDst, err := s.GetTimeZone(); nil != err {94 t.Fatal(err)95 } else {96 t.Logf("GetTimeZone() -> %d,%v", index, autoAdjustDst)97 }98 if index, autoAdjustDst, timeZone, err := s.GetTimeZoneAndRule(); nil != err {99 t.Fatal(err)100 } else {101 t.Logf("GetTimeZoneAndRule() -> %d,%v,\"%s\"", index, autoAdjustDst, timeZone)102 if timeZone, err := s.GetTimeZoneRule(index); nil != err {103 t.Fatal(err)104 } else {105 t.Logf("GetTimeZoneRule(index=%d) -> \"%v\"", index, timeZone)106 }107 }108 if currentTimeServer, err := s.GetTimeServer(); nil != err {109 t.Fatal(err)110 } else {111 t.Logf("GetTimeServer() -> \"%s\"", currentTimeServer)112 }113 if getTimeNowResponse, err := s.GetTimeNow(); nil != err {114 t.Fatal(err)115 } else {116 t.Logf("GetTimeNow() ->")117 t.Logf("\tCurrentUTCTime = \"%s\"", getTimeNowResponse.CurrentUTCTime)118 t.Logf("\tCurrentLocalTime = \"%s\"", getTimeNowResponse.CurrentLocalTime)119 t.Logf("\tCurrentTimeZone = \"%s\"", getTimeNowResponse.CurrentTimeZone)120 t.Logf("\tCurrenTimeGeneration = %d", getTimeNowResponse.CurrentTimeGeneration)121 }122 if currentAlarmList, currentAlarmListVersion, err := s.ListAlarms(); nil != err {123 t.Fatal(err)124 } else {125 t.Logf("ListAlarms() -> \"%s\",\"%s\"", currentAlarmList, currentAlarmListVersion)126 }127 if currentDailyIndexRefreshTime, err := s.GetDailyIndexRefreshTime(); nil != err {128 t.Fatal(err)129 } else {130 t.Logf("GetDailyIndexRefreshTime() -> \"%s\"", currentDailyIndexRefreshTime)131 }132}133//134// AVTransport135//136func TestAVTransport(t *testing.T) {137 s := getTestSonos(sonos.SVC_AV_TRANSPORT)138 if mediaInfo, err := s.GetMediaInfo(0); nil != err {139 t.Fatal(err)140 } else {141 t.Logf("GetMediaInfo(0) ->")142 t.Logf("\tNrTracks = %d", mediaInfo.NrTracks)143 t.Logf("\tMediaDuration = \"%s\"", mediaInfo.MediaDuration)144 t.Logf("\tCurrentURI = \"%s\"", mediaInfo.CurrentURI)145 t.Logf("\tCurrentURIMetaData = \"%s\"", mediaInfo.CurrentURIMetaData)146 t.Logf("\tNextURI = \"%s\"", mediaInfo.NextURI)147 t.Logf("\tNextURIMetaData = \"%s\"", mediaInfo.NextURIMetaData)148 t.Logf("\tPlayMedium = \"%s\"", mediaInfo.PlayMedium)149 t.Logf("\tRecordMedium = \"%s\"", mediaInfo.RecordMedium)150 t.Logf("\tWriteStatus = \"%s\"", mediaInfo.WriteStatus)151 }152 if transportInfo, err := s.GetTransportInfo(0); nil != err {153 t.Fatal(err)154 } else {155 t.Logf("GetTransportInfo(0) ->")156 t.Logf("\tCurrentTransportState = \"%s\"", transportInfo.CurrentTransportState)157 t.Logf("\tCurrentTransportStatus = \"%s\"", transportInfo.CurrentTransportStatus)158 t.Logf("\tCurrentSpeed = \"%s\"", transportInfo.CurrentSpeed)159 }160 if positionInfo, err := s.GetPositionInfo(0); nil != err {161 t.Fatal(err)162 } else {163 t.Logf("GetPositionInfo(0) ->")164 t.Logf("\tTrack = %d", positionInfo.Track)165 t.Logf("\tTrackDuration = \"%s\"", positionInfo.TrackDuration)166 t.Logf("\tTrackMetaData = \"%s\"", positionInfo.TrackMetaData)167 t.Logf("\tTrackURI = \"%s\"", positionInfo.TrackURI)168 t.Logf("\tRelTime = \"%s\"", positionInfo.RelTime)169 t.Logf("\tAbsTime = \"%s\"", positionInfo.AbsTime)170 t.Logf("\tRelCount = %d", positionInfo.RelCount)171 t.Logf("\tAbsCount = %d", positionInfo.AbsCount)172 }173 if deviceCapabilities, err := s.GetDeviceCapabilities(0); nil != err {174 t.Fatal(err)175 } else {176 t.Logf("GetDeviceCapabilities() ->")177 t.Logf("\tPlayMedia = \"%s\"", deviceCapabilities.PlayMedia)178 t.Logf("\tRecMedia = \"%s\"", deviceCapabilities.RecMedia)179 t.Logf("\tRecQualityModes = \"%s\"", deviceCapabilities.RecQualityModes)180 }181 if transportSettings, err := s.GetTransportSettings(0); nil != err {182 t.Fatal(err)183 } else {184 t.Logf("GetTransportSettings() ->")185 t.Logf("\tPlayMode = \"%s\"", transportSettings.PlayMode)186 t.Logf("\tRecQualityMode = \"%s\"", transportSettings.RecQualityMode)187 }188 if crossfadeMode, err := s.GetCrossfadeMode(0); nil != err {189 t.Fatal(err)190 } else {191 t.Logf("GetCrossfadeMode() -> %v", crossfadeMode)192 }193 if actions, err := s.GetCurrentTransportActions(0); nil != err {194 t.Fatal(err)195 } else {196 t.Logf("GetCurrentTransportActions() -> \"%s\"", actions)197 }198 if remainingSleepTimerDuration, currentSleepTimerGeneration, err := s.GetRemainingSleepTimerDuration(0); nil != err {199 t.Fatal(err)200 } else {201 t.Logf("GetRemainingSleepTimerDuration() -> \"%s\",%d", remainingSleepTimerDuration, currentSleepTimerGeneration)202 }203 /*204 if alarmId, groupId, loggedStartTime, err := s.GetRunningAlarmProperties(0); nil != err {205 t.Fatal(err)206 } else {207 t.Logf("GetRunningAlarmProperties() ->")208 t.Logf("\tAlarmID = %d", alarmId)209 t.Logf("\tGroupID = \"%s\"", groupId)210 t.Logf("\tLoggedStartTime = \"%s\"", loggedStartTime)211 }212 */213}214//215// ConnectiionManager216//217func TestConnectionManager(t *testing.T) {218 s := getTestSonos(sonos.SVC_CONNECTION_MANAGER)219 if source, sink, err := s.GetProtocolInfo(); nil != err {220 t.Fatal(err)221 } else {222 t.Logf("GetProtocolInfo() -> \"%s\",\"%s\"", source, sink)223 }224 if connectionIds, err := s.GetCurrentConnectionIDs(); nil != err {225 t.Fatal(err)226 } else {227 t.Logf("GetCurrentConnectionIds() -> \"%s\"", connectionIds)228 }229}230//231// ContentDirectory232// @see also TestBrowse233//234func TestContentDirectory(t *testing.T) {235 s := getTestSonos(sonos.SVC_CONTENT_DIRECTORY)236 if searchCaps, err := s.GetSearchCapabilities(); nil != err {237 t.Fatal(err)238 } else {239 t.Logf("GetSearchCapabilities() -> \"%s\"", searchCaps)240 }241 if sortCaps, err := s.GetSortCapabilities(); nil != err {242 t.Fatal(err)243 } else {244 t.Logf("GetSortCapabilities() -> \"%s\"", sortCaps)245 }246 if id, err := s.GetSystemUpdateID(); nil != err {247 t.Fatal(err)248 } else {249 t.Logf("GetSystemUpdateID() -> \"%s\"", id)250 }251 if albumArtistDisplayOption, err := s.GetAlbumArtistDisplayOption(); nil != err {252 t.Fatal(err)253 } else {254 t.Logf("GetAlbumArtistDisplayOption() -> \"%s\"", albumArtistDisplayOption)255 }256 if lastIndexChange, err := s.GetLastIndexChange(); nil != err {257 t.Fatal(err)258 } else {259 t.Logf("GetLastIndexChange() -> \"%s\"", lastIndexChange)260 }261 if isIndexing, err := s.GetShareIndexInProgress(); nil != err {262 t.Fatal(err)263 } else {264 t.Logf("GetShareIndexInProgress() -> %v", isIndexing)265 }266 if isBrowseable, err := s.GetBrowseable(); nil != err {267 t.Fatal(err)268 } else {269 t.Logf("GetBrowseable() -> %v", isBrowseable)270 }271}272//273// DeviceProperties274//275func TestDeviceProperties(t *testing.T) {276 s := getTestSonos(sonos.SVC_DEVICE_PROPERTIES)277 if currentLEDState, err := s.GetLEDState(); nil != err {278 t.Fatal(err)279 } else {280 t.Logf("GetLEDState() -> \"%s\"", currentLEDState)281 }282 if currentInvisible, err := s.GetInvisible(); nil != err {283 t.Fatal(err)284 } else {285 t.Logf("GetInvisible() -> %v", currentInvisible)286 }287 if currentZoneName, currentIcon, err := s.GetZoneAttributes(); nil != err {288 t.Fatal(err)289 } else {290 t.Logf("GetZoneAttributes() -> \"%s\",\"%s\"", currentZoneName, currentIcon)291 }292 if currentHouseholdId, err := s.GetHouseholdID(); nil != err {293 t.Fatal(err)294 } else {295 t.Logf("GetHouseholdID() -> \"%s\"", currentHouseholdId)296 }297 if zoneInfo, err := s.GetZoneInfo(); nil != err {298 t.Fatal(err)299 } else {300 t.Logf("GetZoneInfo() ->")301 t.Logf("\tSerialNumber = \"%s\"", zoneInfo.SerialNumber)302 t.Logf("\tSoftwareVersion = \"%s\"", zoneInfo.SoftwareVersion)303 t.Logf("\tDisplaySoftwareVersion = \"%s\"", zoneInfo.DisplaySoftwareVersion)304 t.Logf("\tHardwareVersion = \"%s\"", zoneInfo.HardwareVersion)305 t.Logf("\tIPAddress = \"%s\"", zoneInfo.IPAddress)306 t.Logf("\tMACAddress = \"%s\"", zoneInfo.MACAddress)307 t.Logf("\tCopyrightInfo = \"%s\"", zoneInfo.CopyrightInfo)308 t.Logf("\tExtraInfo = \"%s\"", zoneInfo.ExtraInfo)309 }310 if includeLinkedZones, err := s.GetAutoplayLinkedZones(); nil != err {311 t.Fatal(err)312 } else {313 t.Logf("GetAutoplayLinkedZones() -> %v", includeLinkedZones)314 }315 if roomUUID, err := s.GetAutoplayRoomUUID(); nil != err {316 t.Fatal(err)317 } else {318 t.Logf("GetAutoplayRoomUUID() -> \"%s\"", roomUUID)319 }320 if currentVolume, err := s.GetAutoplayVolume(); nil != err {321 t.Fatal(err)322 } else {323 t.Logf("GetAutoplayVolume() -> %d", currentVolume)324 }325 if useVolume, err := s.GetUseAutoplayVolume(); nil != err {326 t.Fatal(err)327 } else {328 t.Logf("GetUseAutoplayVolume() -> %v", useVolume)329 }330}331//332// GroupManagement333//334func TestGroupManagement(t *testing.T) {335 // TODO336}337//338// MusicServices339//340func TestMusicServices(t *testing.T) {341 s := getTestSonos(sonos.SVC_MUSIC_SERVICES)342 if sessionId, err := s.GetSessionId(6 /*iheartradio*/, ""); nil != err {343 t.Fatal(err)344 } else {345 t.Logf("GetSessionId() -> \"%s\"", sessionId)346 }347 if err := s.ListAvailableServices(); nil != err {348 t.Fatal(err)349 } else {350 t.Logf("ListAvailableServices() -> OK")351 }352 if err := s.UpdateAvailableServices(); nil != err {353 t.Fatal(err)354 } else {355 t.Logf("UpdateAvailableServices() -> OK")356 }357}358//359// RenderingControl360//361func TestRenderingControl(t *testing.T) {362 s := getTestSonos(sonos.SVC_RENDERING_CONTROL)363 if currentMute, err := s.GetMute(0, upnp.Channel_Master); nil != err {364 t.Fatal(err)365 } else {366 t.Logf("GetMute() -> %v", currentMute)367 }368 if basicEQ, err := s.ResetBasicEQ(0); nil != err {369 t.Fatal(err)370 } else {371 t.Logf("ResetBasicEQ() ->")372 t.Logf("\tBass = %d", basicEQ.Bass)373 t.Logf("\tTreble = %d", basicEQ.Treble)374 t.Logf("\tLoudness = %v", basicEQ.Loudness)375 t.Logf("\tLeftVolume = %d", basicEQ.LeftVolume)376 t.Logf("\tRightVolume = %d", basicEQ.RightVolume)377 }378 if currentVolume, err := s.GetVolume(0, upnp.Channel_Master); nil != err {379 t.Fatal(err)380 } else {381 t.Logf("GetVolume() -> %d", currentVolume)382 }383 /*384 if currentVolume, err := s.GetVolumeDB(0, upnp.Channel_Master); nil != err {385 t.Fatal(err)386 } else {387 t.Logf("GetVolumeDB() -> %d", currentVolume)388 }389 if min, max, err := s.GetVolumeDBRange(0, upnp.Channel_Master); nil != err {390 t.Fatal(err)391 } else {392 t.Logf("GetVolumeDBRange() -> %d,%d", min, max)393 }394 */395 if currentBass, err := s.GetBass(0); nil != err {396 t.Fatal(err)397 } else {398 t.Logf("GetBass() -> %d", currentBass)399 }400 if currentTreble, err := s.GetTreble(0); nil != err {401 t.Fatal(err)402 } else {403 t.Logf("GetTreble() -> %d", currentTreble)404 }405 if loudness, err := s.GetLoudness(0, upnp.Channel_Master); nil != err {406 t.Fatal(err)407 } else {408 t.Logf("GetLoudness() -> %v", loudness)409 }410 if currentSupportsFixed, err := s.GetSupportsOutputFixed(0); nil != err {411 t.Fatal(err)412 } else {413 t.Logf("GetSupportsOutputFixed() -> %v", currentSupportsFixed)414 }415 if currentFixed, err := s.GetOutputFixed(0); nil != err {416 t.Fatal(err)417 } else {418 t.Logf("GetOutputFixed() -> %v", currentFixed)419 }420 if currentHeadphoneConnected, err := s.GetHeadphoneConnected(0); nil != err {421 t.Fatal(err)422 } else {423 t.Logf("GetHeadphoneConnected() -> %v", currentHeadphoneConnected)424 }425}426//427// SystemProperties428//429func TestSystemProperties(t *testing.T) {430 // TODO431}432//433// ZoneGroupTopology434//435func TestZoneGroupTopology(t *testing.T) {436 s := getTestSonos(sonos.SVC_ZONE_GROUP_TOPOLOGY)437 if updateItem, err := s.CheckForUpdate(upnp.ALL, false, ""); nil != err {438 t.Fatal(err)439 } else {440 t.Logf("CheckForUpdate() ->")441 t.Logf("\tType = \"%s\"", updateItem.Type)442 t.Logf("\tVersion = \"%s\"", updateItem.Version)443 t.Logf("\tUpdateURL = \"%s\"", updateItem.UpdateURL)444 t.Logf("\tDownloadSize = \"%s\"", updateItem.DownloadSize)445 t.Logf("\tManifestURL = \"%s\"", updateItem.ManifestURL)446 }447}448//449// Coverage450//451func TestCoverage(t *testing.T) {452 s := getTestSonos(sonos.SVC_ALL)453 sonos.Coverage(s)454}455//456// Discovery457//458func _TestDiscovery(t *testing.T) {459 if mgr, err := sonos.Discover(TEST_NETWORK, TEST_DISCOVER_PORT); nil != err {460 panic(err)461 } else {462 reactor := sonos.MakeReactor(TEST_NETWORK, TEST_EVENTING_PORT)463 found := sonos.ConnectAny(mgr, reactor, sonos.SVC_DEVICE_PROPERTIES)464 for _, s := range found {465 id, _ := s.GetHouseholdID()466 name, _, _ := s.GetZoneAttributes()467 t.Logf("Found device \"%s\",\"%s\"", id, name)468 }469 }470}471//472// Browse473//474func TestBrowse(t *testing.T) {475 s := getTestSonos(sonos.SVC_CONTENT_DIRECTORY)476 t.Logf("Root Level Children")477 t.Logf("-------------------")478 if result, err := s.GetRootLevelChildren(); nil != err {479 t.Fatal(err)480 } else {481 for _, container := range result {482 t.Logf("%3s %-15s %s", container.ID(), container.Title(), container.Class())483 }484 }485 t.Logf("===================")486 t.Logf("Queues")487 t.Logf("-------------------")488 if result, err := s.ListQueues(); nil != err {489 t.Fatal(err)490 } else {491 for _, container := range result {492 t.Logf("%3s %-15s %s", container.ID(), container.Title(), container.Class())493 }494 }495 t.Logf("===================")496 t.Logf("Saved Queues")497 t.Logf("-------------------")498 if result, err := s.ListSavedQueues(); nil != err {499 t.Fatal(err)500 } else {501 for _, container := range result {502 t.Logf("%-25s %s", container.Title(), container.Class())503 }504 }505 t.Logf("===================")506 t.Logf("Attributes")507 t.Logf("-------------------")508 if result, err := s.ListAttributes(); nil != err {509 t.Fatal(err)510 } else {511 for _, container := range result {512 t.Logf("%-25s %s", container.Title(), container.Class())513 }514 }515 t.Logf("===================")516 t.Logf("Music Shares")517 t.Logf("-------------------")518 if result, err := s.ListMusicShares(); nil != err {519 t.Fatal(err)520 } else {521 for _, container := range result {522 t.Logf("%-25s %s", container.Title(), container.Class())523 }524 }525 t.Logf("===================")526 t.Logf("Genres")527 t.Logf("-------------------")528 if result, err := s.GetAllGenres(); nil != err {529 t.Fatal(err)530 } else {531 for _, container := range result {532 t.Logf("%-25s %s", container.Title(), container.Class())533 }534 }535 t.Logf("===================")536 t.Logf("R&B")537 t.Logf("-------------------")538 var target string539 if result, err := s.GetGenreArtists("R&B"); nil != err {540 t.Fatal(err)541 } else {542 for _, container := range result {543 t.Logf("%-25s %s", container.Title(), container.Class())544 if "John Legend" == container.Title() {545 target = container.ID()546 }547 }548 }549 t.Logf("===================")550 t.Logf("John Legend")551 t.Logf("-------------------")552 if result, err := s.ListChildren(target); nil != err {553 t.Fatal(err)554 } else {555 target = ""556 for _, container := range result {557 t.Logf("%-25s %s", container.Title(), container.Class())558 if "Get Lifted" == container.Title() {559 target = container.ID()560 }561 }562 }563 t.Logf("===================")564 t.Logf("Get Lifted")565 t.Logf("-------------------")566 if result, err := s.ListChildren(target); nil != err {567 t.Fatal(err)568 } else {569 target = ""570 for _, container := range result {571 t.Logf("%-32s %s", container.Title(), container.Class())572 if "I Can Change" == container.Title() {573 target = container.ID()574 }575 }576 }577 t.Logf("===================")578 t.Logf("I Can Change")579 t.Logf("-------------------")580 if result, err := s.GetMetadata(target); nil != err {581 t.Fatal(err)582 } else {583 for _, container := range result {584 t.Logf("%-32s", container.Title())585 }586 }587}588func TestRadio(t *testing.T) {589 // FAILS: It does not seem possible to Browse() R:590 s := getTestSonos(sonos.SVC_CONTENT_DIRECTORY)591 t.Logf("Internet Radio")592 t.Logf("-------------------")593 if result, err := s.ListInternetRadio(); nil != err {594 t.Fatal(err)595 } else {596 for _, container := range result {597 t.Logf("%3s %-25s %s", container.ID(), container.Title(), container.Class())598 }599 }600}601func TestQueue(t *testing.T) {602 // This test prints the current queue, removes the last track603 // in the queue, and then empties the queue completely.604 s := getTestSonos(sonos.SVC_CONTENT_DIRECTORY | sonos.SVC_AV_TRANSPORT)605 var lastId string606 t.Logf("Current Queue")607 t.Logf("-------------------")608 if result, err := s.GetQueueContents(); nil != err {609 t.Fatal(err)610 } else {611 for _, item := range result {612 t.Logf("%6s %s", item.ID(), item.Title())613 lastId = item.ID()614 }615 }616 if "" != lastId {617 if err := s.RemoveTrackFromQueue(0 /*instanceId*/, lastId, 0 /*updateId*/); nil != err {618 t.Fatal(err)619 }620 }621 if err := s.RemoveAllTracksFromQueue(0 /*instanceId*/); nil != err {622 t.Fatal(err)623 }624}625func TestAddTrack(t *testing.T) {626 // This test duplicates the last track at the end of the queue.627 s := getTestSonos(sonos.SVC_CONTENT_DIRECTORY | sonos.SVC_AV_TRANSPORT)628 var lastTrackURI string629 t.Logf("Current Queue")630 t.Logf("-------------------")631 if result, err := s.GetQueueContents(); nil != err {632 t.Fatal(err)633 } else {634 for _, item := range result {635 t.Logf("%#v", item)636 lastTrackURI = item.Res()637 }638 }639 if "" != lastTrackURI {640 req := upnp.AddURIToQueueIn{641 EnqueuedURI: lastTrackURI,642 }643 if result, err := s.AddURIToQueue(0 /*instanceId*/, &req); nil != err {644 t.Fatal(err)645 } else {646 t.Logf("%#v", result)647 }648 }649}650func TestAddAlbum(t *testing.T) {651 // Replace the current queue (Q:0) with George Harrison's Dark Horse652 s := getTestSonos(sonos.SVC_CONTENT_DIRECTORY | sonos.SVC_AV_TRANSPORT)653 if err := s.RemoveAllTracksFromQueue(0 /*instanceId*/); nil != err {654 t.Fatal(err)655 }656 if objs, err := s.GetMetadata("A:ALBUM/Dark Horse"); nil != err {657 t.Fatal(err)658 } else {659 req := upnp.AddURIToQueueIn{660 EnqueuedURI: objs[0].Res(),661 }662 if result, err := s.AddURIToQueue(0 /*instanceId*/, &req); nil != err {663 t.Fatal(err)664 } else {665 t.Logf("Added %d new track(s)", result.NumTracksAdded)666 }667 }668}669func TestRemoveRange(t *testing.T) {670 // This test removes the first two tracks from the queue.671 s := getTestSonos(sonos.SVC_CONTENT_DIRECTORY | sonos.SVC_AV_TRANSPORT)672 updateId, err := s.RemoveTrackRangeFromQueue(0, /*instanceId*/673 0, /*updateId*/674 1, /*startingIndex*/675 2 /*numberofTracks*/)676 if nil != err {677 t.Fatal(err)678 } else {679 t.Logf("New UpdateId = %d", updateId)680 }681}682func TestReorder(t *testing.T) {683 // This test moves the first two tracks of Sgt. Pepper to the end.684 s := getTestSonos(sonos.SVC_CONTENT_DIRECTORY | sonos.SVC_AV_TRANSPORT)685 err := s.ReorderTracksInQueue(0, /*instanceId*/686 1, /*startingIndex*/687 2, /*numberOfTracks*/688 14, /*insertBefore*/689 0 /*updateId*/)690 if nil != err {691 t.Fatal(err)692 }693}694func TestGetCurrentTransportActions(t *testing.T) {695 // This test prints the currently available transport actions696 s := getTestSonos(sonos.SVC_CONTENT_DIRECTORY | sonos.SVC_AV_TRANSPORT)697 if actions, err := s.GetCurrentTransportActions(0 /*instanceId*/); nil != err {698 t.Fatal(err)699 } else {700 for _, action := range actions {701 t.Logf(action)702 }703 }704}705func TestNamedQueue(t *testing.T) {706 // This test creates a new named queue and then deletes it707 s := getTestSonos(sonos.SVC_CONTENT_DIRECTORY | sonos.SVC_AV_TRANSPORT)708 obj, err := s.SaveQueue(0 /*instanceId*/, "borodin" /*title*/, "" /*objectId*/)709 if nil != err {710 t.Fatal(err)711 } else {712 t.Logf("%#v", obj)713 if err = s.DestroyObject(obj); nil != err {714 t.Fatal(err)715 } else {716 t.Logf("queue removed")717 }718 }719}720func TestPositionInfo(t *testing.T) {721 // This test fetches and prints the current position info722 s := getTestSonos(sonos.SVC_CONTENT_DIRECTORY | sonos.SVC_AV_TRANSPORT)723 if info, err := s.GetPositionInfo(0 /*instanceId*/); nil != err {724 t.Fatal(err)725 } else {726 t.Logf("%d", info.Track)727 t.Logf("%s", info.TrackDuration)728 t.Logf("%s", info.TrackMetaData)729 t.Logf("%s", info.TrackURI)730 t.Logf("%s", info.RelTime)731 t.Logf("%s", info.AbsTime)732 t.Logf("%d", info.RelCount)733 t.Logf("%d", info.AbsCount)734 }735}736func TestMediaInfo(t *testing.T) {737 // This test fetches and prints the current media info738 s := getTestSonos(sonos.SVC_CONTENT_DIRECTORY | sonos.SVC_AV_TRANSPORT)739 if info, err := s.GetMediaInfo(0 /*instanceId*/); nil != err {740 t.Fatal(err)741 } else {742 t.Logf("%#v", info.NrTracks)743 t.Logf("%#v", info.MediaDuration)744 t.Logf("%#v", info.CurrentURI)745 t.Logf("%#v", info.CurrentURIMetaData)746 t.Logf("%#v", info.NextURI)747 t.Logf("%#v", info.NextURIMetaData)748 t.Logf("%#v", info.PlayMedium)749 t.Logf("%#v", info.RecordMedium)750 t.Logf("%#v", info.WriteStatus)751 }752}753func TestDeviceCapabilities(t *testing.T) {754 // This test fetches and prints the capabilities of the current device755 s := getTestSonos(sonos.SVC_CONTENT_DIRECTORY | sonos.SVC_AV_TRANSPORT)756 if caps, err := s.GetDeviceCapabilities(0 /*instanceId*/); nil != err {757 t.Fatal(err)758 } else {759 t.Logf("%#v", caps.PlayMedia)760 t.Logf("%#v", caps.RecMedia)761 t.Logf("%#v", caps.RecQualityModes)762 }763}764func TestNavigation(t *testing.T) {765 // Test of the Next and Previous methods766 s := getTestSonos(sonos.SVC_CONTENT_DIRECTORY | sonos.SVC_AV_TRANSPORT)767 if err := s.Next(0 /*instanceId*/); nil != err {768 t.Fatal(err)769 }770 if err := s.Previous(0 /*instanceId*/); nil != err {771 t.Fatal(err)772 }773}774func TestPlayPauseStop(t *testing.T) {775 // Test of the Play, Pause, and Stop methods776 s := getTestSonos(sonos.SVC_CONTENT_DIRECTORY | sonos.SVC_AV_TRANSPORT)777 if info, err := s.GetTransportInfo(0); nil != err {778 t.Fatal(err)779 } else {780 if upnp.State_PAUSED_PLAYBACK == info.CurrentTransportState {781 s.Stop(0 /*instanceId*/)782 } else if upnp.State_STOPPED == info.CurrentTransportState {783 s.Play(0 /*instanceId*/, upnp.PlaySpeed_1)784 } else if upnp.State_PLAYING == info.CurrentTransportState {785 s.Pause(0 /*instanceId*/)786 }787 }788}789func TestAddMultiple(t *testing.T) {790 // This test adds Reptile from NIN and Reset from Big Boi to the791 // queue using AddMultipleURIsToQueue. Note that the containing792 // album must be known to find the track.793 s := getTestSonos(sonos.SVC_CONTENT_DIRECTORY | sonos.SVC_AV_TRANSPORT)794 var tracks_uri string795 if objs, err := s.GetMetadata("A:TRACKS"); nil != err {796 t.Fatal(err)797 } else {798 tracks_uri = objs[0].Res()799 }800 var uris []string801 if objs, err := s.GetTrackFromAlbum("The Downward Spiral", "Reptile"); nil != err {802 t.Fatal(err)803 } else {804 for _, obj := range objs {805 uris = append(uris, obj.Res())806 }807 }808 if objs, err := s.GetTrackFromAlbum("Speakerboxxx", "Reset"); nil != err {809 t.Fatal(err)810 } else {811 for _, obj := range objs {812 uris = append(uris, obj.Res())813 }814 }815 enqueued_uris := strings.Join(uris, " ")816 req := &upnp.AddMultipleURIsToQueueIn{817 UpdateID: 0,818 NumberOfURIs: uint32(len(uris)),819 EnqueuedURIs: enqueued_uris,820 EnqueuedURIsMetaData: didl.EmptyDocuments(len(uris)),821 ContainerURI: tracks_uri,822 ContainerMetaData: didl.EmptyDocument(),823 DesiredFirstTrackNumberEnqueued: 0,824 EnqueueAsNext: false,825 }826 if resp, err := s.AddMultipleURIsToQueue(0 /*instanceId*/, req); nil != err {827 t.Fatal(err)828 } else {829 t.Logf("%#v", resp)830 }831}832func TestSeek(t *testing.T) {833 // A test that sets playback to 30 seconds from the beginning834 // of the fifth track in the queue.835 s := getTestSonos(sonos.SVC_CONTENT_DIRECTORY | sonos.SVC_AV_TRANSPORT)836 if err := s.Seek(0 /*instanceId*/, upnp.SeekMode_TRACK_NR, "6"); nil != err {837 t.Fatal(err)838 }839 if err := s.Seek(0 /*instanceId*/, upnp.SeekMode_REL_TIME, "0:0:30"); nil != err {840 t.Fatal(err)841 }842}843func TestUseQueue(t *testing.T) {844 // Select the current queue (Q:0) (e.g., if we were already845 // listening to the radio)846 s := getTestSonos(sonos.SVC_CONTENT_DIRECTORY | sonos.SVC_AV_TRANSPORT)847 if info, err := s.GetMediaInfo(0 /*instanceId*/); nil != err {848 t.Fatal(err)849 } else if sonos.ObjectID_Queue_AVT_Instance_0 != info.CurrentURI {850 if data, err := s.GetMetadata(sonos.ObjectID_Queue_AVT_Instance_0); nil != err {851 t.Fatal(err)852 } else {853 if err := s.SetAVTransportURI(0 /*instanceId*/, data[0].Res(), "" /*metadata*/); nil != err {854 t.Fatal(err)855 }856 }857 }858}859func TestTransportSettings(t *testing.T) {860 // Get the current playback mode and recording quality861 s := getTestSonos(sonos.SVC_CONTENT_DIRECTORY | sonos.SVC_AV_TRANSPORT)862 if data, err := s.GetTransportSettings(0 /*instanceId*/); nil != err {863 t.Fatal(err)864 } else {865 t.Logf("%#v", data)866 }867}868func TestSetPlayMode(t *testing.T) {869 // Changes the playback mode to shuffle, tries to set it to some870 // garbage value, then reverts it to normal.871 s := getTestSonos(sonos.SVC_CONTENT_DIRECTORY | sonos.SVC_AV_TRANSPORT)872 if err := s.SetPlayMode(0 /*instanceId*/, upnp.PlayMode_SHUFFLE); nil != err {873 t.Fatal(err)874 } else if err := s.SetPlayMode(0 /*instanceId*/, "SOMETHING_INVALID"); nil != err {875 s.SetPlayMode(0 /*instanceId*/, upnp.PlayMode_NORMAL)876 }877}878func TestSections(t *testing.T) {879 // Advance to the next section, then return to the previous section880 s := getTestSonos(sonos.SVC_CONTENT_DIRECTORY | sonos.SVC_AV_TRANSPORT)881 if err := s.NextSection(0); nil != err {882 t.Error(err)883 }884 if err := s.PreviousSection(0); nil != err {885 t.Error(err)886 }887}888func TestCrossfadeMode(t *testing.T) {889 // Tests setting and geting crossfade mode890 s := getTestSonos(sonos.SVC_AV_TRANSPORT)891 var mode, pmode bool892 var err error893 if pmode, err = s.GetCrossfadeMode(0 /*instanceId*/); nil != err {894 t.Fatal(err)895 }896 mode = !pmode897 if err = s.SetCrossfadeMode(0 /*instanceId*/, mode); nil != err {898 t.Fatal(err)899 }900 if pmode, err = s.GetCrossfadeMode(0 /*instanceId*/); nil != err {901 t.Fatal(err)902 }903 if mode != pmode {904 t.Error("GetCrossfadeMode failed to set crossfade mode")905 }906 if err = s.SetCrossfadeMode(0 /*instanceId*/, false); nil != err {907 t.Fatal(err)908 }909}910func TestGetZoneInfo(t *testing.T) {911 // Tests getting basic information about the Sonos appliance912 s := getTestSonos(sonos.SVC_DEVICE_PROPERTIES)913 if info, err := s.GetZoneInfo(); nil != err {914 t.Fatal(err)915 } else {916 t.Logf("%#v", info)917 }918}919func TestGetZoneGroup(t *testing.T) {920 // Tests getting basic information about the Sonos appliance921 s := getTestSonos(sonos.SVC_ZONE_GROUP_TOPOLOGY)922 if info, err := s.GetZoneGroupAttributes(); nil != err {923 t.Fatal(err)924 } else {925 t.Logf("%#v", info)926 }927}928func handleEvent_TestEvent(reactor upnp.Reactor, c chan bool) {929 for {930 select {931 case evt := <-reactor.Channel():932 switch evt.Type() {933 case upnp.AlarmClock_EventType:934 b := evt.(upnp.AlarmClockEvent)935 log.Printf("%#v", b)936 case upnp.AVTransport_EventType:937 b := evt.(upnp.AVTransportEvent)938 log.Printf("%#v", b)939 case upnp.ConnectionManager_EventType:...

Full Screen

Full Screen

wrap.go

Source:wrap.go Github

copy

Full Screen

...20// Wrap is identical to WrapWithID with the exception that it uses the default log ID.21func Wrap(h http.Handler, options ...logging.LoggerOption) http.Handler {22 return WrapWithID(h, DefaultLogID, options...)23}24// Logf logs with the given severity. Remaining arguments are handled in the manner of fmt.Printf.25// This should be called from a handler that has been wrapped with Wrap or WrapWithID. If it is26// called from a handler that has not been wrapped then messages are simply logged using the standard27// library's log package.28func Logf(ctx context.Context, severity logging.Severity, format string, v ...interface{}) {29 cv := ctx.Value(ctxKey)30 if cv == nil {31 // No logger in the context, so the handler wasn't wrapped.32 log.Printf(format, v...)33 return34 }35 logger := cv.(*Logger)36 logger.Logf(severity, format, v...)37}38// Debugf calls Logf with debug severity.39func Debugf(ctx context.Context, format string, v ...interface{}) {40 Logf(ctx, logging.Debug, format, v...)41}42// Infof calls Logf with info severity.43func Infof(ctx context.Context, format string, v ...interface{}) {44 Logf(ctx, logging.Info, format, v...)45}46// Noticef calls Logf with notice severity.47func Noticef(ctx context.Context, format string, v ...interface{}) {48 Logf(ctx, logging.Notice, format, v...)49}50// Warningf calls Logf with warning severity.51func Warningf(ctx context.Context, format string, v ...interface{}) {52 Logf(ctx, logging.Warning, format, v...)53}54// Errorf calls Logf with error severity.55func Errorf(ctx context.Context, format string, v ...interface{}) {56 Logf(ctx, logging.Error, format, v...)57}58// Criticalf calls Logf with critical severity.59func Criticalf(ctx context.Context, format string, v ...interface{}) {60 Logf(ctx, logging.Critical, format, v...)61}62// Alertf calls Logf with alert severity.63func Alertf(ctx context.Context, format string, v ...interface{}) {64 Logf(ctx, logging.Alert, format, v...)65}66// Emergencyf calls Logf with emergency severity.67func Emergencyf(ctx context.Context, format string, v ...interface{}) {68 Logf(ctx, logging.Emergency, format, v...)69}70// Log logs with the given severity. v must be either a string, or something that71// marshals via the encoding/json package to a JSON object (and not any other type72// of JSON value). This should be called from a handler that has been wrapped with73// Wrap or WrapWithID. If it is called from a handler that has not been wrapped74// then messages are simply logged using the standard library's log package.75func Log(ctx context.Context, severity logging.Severity, v interface{}) {76 cv := ctx.Value(ctxKey)77 if cv == nil {78 // No logger in the context, so the handler wasn't wrapped.79 log.Print(v)80 return81 }82 logger := cv.(*Logger)...

Full Screen

Full Screen

main.go

Source:main.go Github

copy

Full Screen

...10 nodes := lock.Nodes("127.0.0.1:2379")11 resourceId := "id123456"12 go func() {13 lc := etcd.NewLock(nodes)14 log.Logf("协程1获取锁...")15 // 获取锁16 err := lc.Acquire(resourceId)17 if err != nil {18 log.Logf("[ERR] 协程1未得到锁")19 return20 }21 log.Logf("协程1得到锁,等一秒")22 time.Sleep(1 * time.Second)23 // 释放锁24 log.Logf("协程1释放锁")25 err = lc.Release(resourceId)26 if err != nil {27 log.Fatal(err)28 }29 }()30 go func() {31 lc := etcd.NewLock(nodes)32 log.Logf("协程2获取锁...")33 // 获取锁34 err := lc.Acquire(resourceId)35 if err != nil {36 log.Logf("[ERR] 协程2未得到锁")37 return38 }39 log.Logf("协程2得到锁,等一秒")40 time.Sleep(1 * time.Second)41 // 释放锁42 log.Logf("协程2释放锁")43 err = lc.Release(resourceId)44 if err != nil {45 log.Fatal(err)46 }47 }()48 go func() {49 lc := etcd.NewLock(nodes)50 log.Logf("协程3获取锁...")51 // 获取锁52 err := lc.Acquire(resourceId)53 if err != nil {54 log.Logf("[ERR] 协程3未得到锁")55 return56 }57 log.Logf("协程3得到锁,等一秒")58 time.Sleep(1 * time.Second)59 // 释放锁60 log.Logf("协程3释放锁")61 err = lc.Release(resourceId)62 if err != nil {63 log.Fatal(err)64 }65 }()66 go func() {67 lc := etcd.NewLock(nodes)68 log.Logf("协程4获取锁...")69 // 获取锁70 err := lc.Acquire(resourceId)71 if err != nil {72 log.Logf("[ERR] 协程3未得到锁")73 return74 }75 log.Logf("协程4得到锁,等一秒")76 time.Sleep(1 * time.Second)77 // 释放锁78 log.Logf("协程4释放锁")79 err = lc.Release(resourceId)80 if err != nil {81 log.Fatal(err)82 }83 }()84 go func() {85 lc := etcd.NewLock(nodes)86 log.Logf("协程5获取锁...")87 // 获取锁88 err := lc.Acquire(resourceId)89 if err != nil {90 log.Logf("[ERR] 协程5未得到锁")91 return92 }93 log.Logf("协程5得到锁,等一秒")94 time.Sleep(1 * time.Second)95 // 释放锁96 log.Logf("协程5释放锁")97 err = lc.Release(resourceId)98 if err != nil {99 log.Fatal(err)100 }101 }()102 go func() {103 lc := etcd.NewLock(nodes)104 log.Logf("协程6获取锁...")105 // 获取锁106 err := lc.Acquire(resourceId)107 if err != nil {108 log.Logf("[ERR] 协程6未得到锁")109 return110 }111 log.Logf("协程6得到锁,等一秒")112 time.Sleep(1 * time.Second)113 // 释放锁114 log.Logf("协程6释放锁")115 err = lc.Release(resourceId)116 if err != nil {117 log.Fatal(err)118 }119 }()120 // 等协程跑完121 time.Sleep(5 * time.Second)122}...

Full Screen

Full Screen

Logf

Using AI Code Generation

copy

Full Screen

1import (2func main() {3log.Printf("hello, world4}5func Logln(v ...interface{})6func Logln(v ...interface{})7import (8func main() {9log.Println("hello, world")10}11The LogFatal method of log class is used to print the log message and call the os.Exit(1) function. The LogFatal method of log class is defined as follows:12func LogFatal(v ...interface{})13The LogFatal method of log class prints the log message and call the os.Exit(1) function. The LogFatal method of log class is defined as follows:14func LogFatal(v ...interface{})15import (16func main() {17log.Fatal("hello, world")18}19func LogPanic(v ...interface{})20func LogPanic(v ...interface{})21import (22func main() {23log.Panic("hello, world")24}

Full Screen

Full Screen

Logf

Using AI Code Generation

copy

Full Screen

1import (2func main() {3log.Printf("Hello World")4}5func Println(v ...interface{})6import (7func main() {8log.Println("Hello World")9}10func Print(v ...interface{})11import (12func main() {13log.Print("Hello World")14}15func Fatal(v ...interface{})16import (17func main() {18log.Fatal("Hello World")19}20func Fatalf(format string, v ...interface{})21import (22func main() {23log.Fatalf("Hello World")24}

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Syzkaller automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful