unit_topic_test.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /*
  2. * Copyright (c) 2013 IBM Corp.
  3. *
  4. * All rights reserved. This program and the accompanying materials
  5. * are made available under the terms of the Eclipse Public License v1.0
  6. * which accompanies this distribution, and is available at
  7. * http://www.eclipse.org/legal/epl-v10.html
  8. *
  9. * Contributors:
  10. * Seth Hoenig
  11. * Allan Stockdill-Mander
  12. * Mike Robertson
  13. */
  14. package mqtt
  15. import (
  16. "testing"
  17. )
  18. func Test_ValidateTopicAndQos_qos3(t *testing.T) {
  19. e := validateTopicAndQos("a", 3)
  20. if e != ErrInvalidQos {
  21. t.Fatalf("invalid error for invalid qos")
  22. }
  23. }
  24. func Test_ValidateTopicAndQos_ES(t *testing.T) {
  25. e := validateTopicAndQos("", 0)
  26. if e != ErrInvalidTopicEmptyString {
  27. t.Fatalf("invalid error for empty topic name")
  28. }
  29. }
  30. func Test_ValidateTopicAndQos_a_0(t *testing.T) {
  31. e := validateTopicAndQos("a", 0)
  32. if e != nil {
  33. t.Fatalf("error from valid NewTopicFilter")
  34. }
  35. }
  36. func Test_ValidateTopicAndQos_H(t *testing.T) {
  37. e := validateTopicAndQos("a/#/c", 0)
  38. if e != ErrInvalidTopicMultilevel {
  39. t.Fatalf("invalid error for bad multilevel topic filter")
  40. }
  41. }